修复无法结束会话的问题

This commit is contained in:
zyc404 2023-03-03 19:57:59 +08:00
parent fe4e7ad4d7
commit ff8b165ca6
2 changed files with 15 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import SydneyAIClient from '../utils/SydneyAIClient.js'
import { render, getMessageById, makeForwardMsg, tryTimes, upsertMessage, randomString } from '../utils/common.js'
import { ChatGPTPuppeteer } from '../utils/browser.js'
import { KeyvFile } from 'keyv-file'
import Keyv from 'keyv'
import { OfficialChatGPTClient } from '../utils/message.js'
import fetch from 'node-fetch'
import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js'
@ -153,8 +154,13 @@ export class chatgpt extends plugin {
await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
} else if (use === 'bing' && Config.bingStyle === 'Sydney') {
const conversation = new KeyvFile({ filename: 'cache.json' })
await conversation.delete(`SydneyUser_${e.sender.user_id}`);
const conversation = {
store: new KeyvFile({ filename: 'cache.json' }),
namespace: 'Sydney',
}
const conversationsCache = new Keyv(conversation)
console.log(`SydneyUser_${e.sender.user_id}`,await conversationsCache.get(`SydneyUser_${e.sender.user_id}`))
await conversationsCache.delete(`SydneyUser_${e.sender.user_id}`)
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
} else {
let c = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
@ -173,8 +179,12 @@ export class chatgpt extends plugin {
await redis.del(`CHATGPT:QQ_CONVERSATION:${qq}`)
await this.reply(`${atUser}已退出TA当前的对话TA仍可以@我进行聊天以开启新的对话`, true)
} else if (use === 'bing' && Config.bingStyle === 'Sydney') {
const conversation = new KeyvFile({ filename: 'cache.json' })
await conversation.delete(`SydneyUser_${qq}`);
const conversation = {
store: new KeyvFile({ filename: 'cache.json' }),
namespace: 'Sydney',
}
const conversationsCache = new Keyv(conversation)
await conversationsCache.delete(`SydneyUser_${qq}`)
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
} else {
let c = await redis.get(`CHATGPT:CONVERSATIONS:${qq}`)

View file

@ -171,7 +171,7 @@ export default class SydneyAIClient {
// Due to this jailbreak, the AI will occasionally start responding as the user. It only happens rarely (and happens with the non-jailbroken Bing too), but since we are handling conversations ourselves now, we can use this system to ignore the part of the generated message that is replying as the user.
const stopToken = '[user](#message)';
const conversationKey = `SydneyUser_${opts.user}`;
const conversationKey = `SydneyUser_${this.opts.user}`;
const conversation = (await this.conversationsCache.get(conversationKey)) || {
messages: [],
createdAt: Date.now(),