fix: recall; change style

This commit is contained in:
葛胤池 2022-12-11 13:38:37 +08:00
parent 85b0d68e7e
commit e5f0ada32e
3 changed files with 41 additions and 30 deletions

View file

@ -79,13 +79,14 @@ export class chatgpt extends plugin {
markdown: true, markdown: true,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
}) })
logger.info('chatgpt插件已加载')
} }
/** /**
* 获取chatgpt当前对话列表 * 获取chatgpt当前对话列表
* @param e * @param e
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getConversations (e) { async getConversations (e) {
let keys = await redis.keys('CHATGPT:CONVERSATIONS:*') let keys = await redis.keys('CHATGPT:CONVERSATIONS:*')
if (!keys || keys.length === 0) { if (!keys || keys.length === 0) {
@ -104,10 +105,10 @@ export class chatgpt extends plugin {
} }
/** /**
* 销毁指定人的对话 * 销毁指定人的对话
* @param e * @param e
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async destroyConversations (e) { async destroyConversations (e) {
let ats = e.message.filter(m => m.type === 'at') let ats = e.message.filter(m => m.type === 'at')
if (ats.length === 0) { if (ats.length === 0) {
@ -134,11 +135,11 @@ export class chatgpt extends plugin {
async help (e) { async help (e) {
let response = 'chatgpt-plugin使用帮助文字版\n' + let response = 'chatgpt-plugin使用帮助文字版\n' +
'@我+聊天内容: 发起对话与AI进行聊天\n' + '@我+聊天内容: 发起对话与AI进行聊天\n' +
'#chatgpt对话列表: 查看当前发起的对话\n' + '#chatgpt对话列表: 查看当前发起的对话\n' +
'#结束对话: 结束自己或@用户的对话\n' + '#结束对话: 结束自己或@用户的对话\n' +
'#chatgpt帮助: 查看本帮助\n' + '#chatgpt帮助: 查看本帮助\n' +
'源代码https://github.com/ikechan8370/chatgpt-plugin' '源代码https://github.com/ikechan8370/chatgpt-plugin'
await this.reply(response) await this.reply(response)
} }
@ -167,9 +168,9 @@ export class chatgpt extends plugin {
} }
/** /**
* #chatgpt * #chatgpt
* @param e oicq传递的事件参数e * @param e oicq传递的事件参数e
*/ */
async chatgpt (e) { async chatgpt (e) {
if (!e.msg || e.msg.startsWith('#')) { if (!e.msg || e.msg.startsWith('#')) {
return return
@ -188,7 +189,7 @@ export class chatgpt extends plugin {
await this.reply(`OpenAI认证失败请检查Token${e}`, true) await this.reply(`OpenAI认证失败请检查Token${e}`, true)
return return
} }
await this.reply('我正在思考如何回复你,请稍等', true, 5) await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 5 })
let c let c
logger.info(`chatgpt question: ${question}`) logger.info(`chatgpt question: ${question}`)
let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`) let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
@ -239,11 +240,14 @@ export class chatgpt extends plugin {
} }
} }
if (userSetting.usePicture) { if (userSetting.usePicture) {
while (!response.trimEnd().endsWith('.') && !response.trimEnd().endsWith('。') && !response.trimEnd().endsWith('……') && let endTokens = ['.', '。', '……', '!', '', ']', ')', '', '】', '?', '', '~']
!response.trimEnd().endsWith('') && !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith(']') && !response.trimEnd().endsWith('】') while (!endTokens.find(token => response.trimEnd().endsWith(token))) {
) { // while (!response.trimEnd().endsWith('.') && !response.trimEnd().endsWith('。') && !response.trimEnd().endsWith('……') &&
await this.reply('内容有点多,我正在奋笔疾书,请再等一会', true, 5) // !response.trimEnd().endsWith('') && !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith(']') && !response.trimEnd().endsWith('】')
// ) {
await this.reply('内容有点多,我正在奋笔疾书,请再等一会', true, { recallMsg: 5 })
const responseAppend = await c.sendMessage('Continue') const responseAppend = await c.sendMessage('Continue')
// console.log(responseAppend)
// 检索是否有屏蔽词 // 检索是否有屏蔽词
const blockWord = blockWords.split(',').find(word => responseAppend.toLowerCase().includes(word.toLowerCase())) const blockWord = blockWords.split(',').find(word => responseAppend.toLowerCase().includes(word.toLowerCase()))
if (blockWord) { if (blockWord) {
@ -251,7 +255,7 @@ export class chatgpt extends plugin {
return return
} }
if (responseAppend.indexOf('conversation') > -1 || responseAppend.startsWith("I'm sorry")) { if (responseAppend.indexOf('conversation') > -1 || responseAppend.startsWith("I'm sorry")) {
logger.warn('chatgpt might forgot what it had said') logger.warn('chatgpt might forget what it had said')
break break
} }
// 更新redis中的conversation对象因为send后c已经被自动更新了 // 更新redis中的conversation对象因为send后c已经被自动更新了

View file

@ -36,23 +36,27 @@ body {
margin-bottom: 5px; margin-bottom: 5px;
} }
.question { .question {
background: #009FFF; /* fallback for old browsers */ background: #C6FFDD; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #ec2F4B, #009FFF); /* Chrome 10-25, Safari 5.1-6 */ background: -webkit-linear-gradient(to right, #f7797d, #FBD786, #C6FFDD); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #ec2F4B, #009FFF); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ background: linear-gradient(to right, #f7797d, #FBD786, #C6FFDD); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
color: #000000;
text-shadow: 0 0 10px white;
font-weight: bold;
border-radius: 5px; border-radius: 5px;
padding: 8px 10px; padding: 8px 10px;
margin-bottom: 10px; margin-bottom: 10px;
box-shadow: 0 5px 10px 0 rgb(0 0 0 / 15%);
}
.question span {
color: #000000;
/*text-shadow: 0 0 10px white;*/
font-weight: bold;
} }
.answer { .answer {
position: relative; position: relative;
border-radius: 5px; border-radius: 5px;
padding: 8px 10px; padding: 8px 10px;
background: #dbe9ff; background: #dbe9ff;
width: 100%; width: 100%;
box-shadow: 0 5px 10px 0 rgb(0 0 0 / 15%);
line-height: 25px;
} }
.logo { .logo {

View file

@ -15,7 +15,10 @@
<!-- {{senderName}}--> <!-- {{senderName}}-->
<!-- </div>--> <!-- </div>-->
<div class="question"> <div class="question">
{{question}} <span>
{{question}}
</span>
</div> </div>
<div class="answer"> <div class="answer">
<div id="content"> <div id="content">