diff --git a/apps/chat.js b/apps/chat.js index ab2a700..d551186 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -5,9 +5,11 @@ import { v4 as uuid } from 'uuid' import delay from 'delay' import { ChatGPTAPI } from 'chatgpt' import { ChatGPTClient, BingAIClient } from '@waylaidwanderer/chatgpt-api' +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' @@ -155,6 +157,15 @@ export class chatgpt extends plugin { if (use === 'api3') { await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`) await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true) + } else if (use === 'bing' && Config.toneStyle === 'Sydney') { + 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}`) if (!c) { @@ -171,6 +182,14 @@ export class chatgpt extends plugin { if (use === 'api3') { await redis.del(`CHATGPT:QQ_CONVERSATION:${qq}`) await this.reply(`${atUser}已退出TA当前的对话,TA仍可以@我进行聊天以开启新的对话`, true) + } else if (use === 'bing' && Config.toneStyle === 'Sydney') { + 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}`) if (!c) { @@ -448,7 +467,7 @@ export class chatgpt extends plugin { previousConversation = JSON.parse(previousConversation) conversation = { conversationId: previousConversation.conversation.conversationId, - parentMessageId: previousConversation.conversation.parentMessageId, + parentMessageId: previousConversation.parentMessageId, clientId: previousConversation.clientId, invocationId: previousConversation.invocationId, conversationSignature: previousConversation.conversationSignature @@ -468,6 +487,7 @@ export class chatgpt extends plugin { if (use === 'bing') { previousConversation.clientId = chatMessage.clientId previousConversation.invocationId = chatMessage.invocationId + previousConversation.parentMessageId = chatMessage.parentMessageId previousConversation.conversationSignature = chatMessage.conversationSignature } else { // 或许这样切换回来不会404? @@ -576,6 +596,7 @@ export class chatgpt extends plugin { quote: quote.length > 0, quotes: quote, cache: cacheData, + style: Config.toneStyle, version }, { retType: Config.quoteReply ? 'base64' : '' }), e.isGroup && Config.quoteReply) } @@ -602,12 +623,30 @@ export class chatgpt extends plugin { if (bingToken?.indexOf('=') > -1) { cookie = bingToken } - const bingAIClient = new BingAIClient({ - userToken: bingToken, // "_U" cookie from bing.com - cookie, - debug: Config.debug, - proxy: Config.proxy - }) + let bingAIClient + if (Config.bingStyle === 'Sydney') { + const cacheOptions = { + namespace: 'Sydney', + store: new KeyvFile({ filename: 'cache.json' }), + } + bingAIClient = new SydneyAIClient({ + userToken: bingToken, // "_U" cookie from bing.com + cookie, + debug: Config.debug, + cache: cacheOptions, + user: e.sender.user_id + }) + // Sydney不实现上下文传递,删除上下文索引 + delete conversation.clientId + delete conversation.invocationId + delete conversation.conversationSignature + } else { + bingAIClient = new BingAIClient({ + userToken: bingToken, // "_U" cookie from bing.com + cookie, + debug: Config.debug + }) + } let response let reply = '' try { @@ -642,7 +681,8 @@ export class chatgpt extends plugin { conversationId: response.conversationId, clientId: response.clientId, invocationId: response.invocationId, - conversationSignature: response.conversationSignature + conversationSignature: response.conversationSignature, + parentMessageId: response.messageId } } case 'api3': { diff --git a/guoba.support.js b/guoba.support.js index f27fd10..cd4a27d 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -200,13 +200,37 @@ export function supportGuoba () { { field: 'temperature', label: 'temperature', - bottomHelpMessage: 'temperature。', + bottomHelpMessage: '用于控制回复内容的多样性,数值越大回复越加随机、多元化,数值越小回复越加保守。', component: 'InputNumber', componentProps: { min: 0, max: 2 } }, + { + label: '以下为必应方式的配置。', + component: 'Divider' + }, + { + field: 'toneStyle', + label: 'Bing模式', + bottomHelpMessage: '微软必应官方的三种应答风格。默认为均衡,Sydney为实验风格,独立与三种风格之外。', + component: 'Select', + componentProps: { + options: [ + { label: '均衡', value: 'balanced' }, + { label: '创意', value: 'creative' }, + { label: '精确', value: 'precise' }, + { label: 'Sydney(可能存在风险)', value: 'Sydney' } + ] + } + }, + { + field: 'sydney', + label: 'Sydney的设定', + bottomHelpMessage: '你可以自己改写Sydney的设定,让Sydney变成你希望的样子,不过请注意,Sydney仍然是Sydney。', + component: 'InputTextArea' + }, { label: '以下为API3方式的配置。', component: 'Divider' @@ -262,19 +286,6 @@ export function supportGuoba () { label: '验证码平台Token', bottomHelpMessage: '可注册2captcha实现跳过验证码,收费服务但很便宜。否则可能会遇到验证码而卡住。', component: 'InputPassword' - }, - { - field: 'toneStyle', - label: 'Bing模式', - bottomHelpMessage: '微软必应官方的三种应答风格。默认为均衡', - component: 'Select', - componentProps: { - options: [ - { label: '均衡', value: 'balanced' }, - { label: '创意', value: 'creative' }, - { label: '精确', value: 'precise' } - ] - } } ], // 获取配置数据方法(用于前端填充显示数据) diff --git a/resources/content/Bing/index.html b/resources/content/Bing/index.html index c2b00c5..9cce772 100644 --- a/resources/content/Bing/index.html +++ b/resources/content/Bing/index.html @@ -1,4 +1,4 @@ - + @@ -13,7 +13,7 @@ - +