fix: no support cache

This commit is contained in:
ikechan8370 2023-03-04 11:41:39 +08:00
parent 90c7c992a6
commit 5ceb9c9de3
3 changed files with 23 additions and 15 deletions

View file

@ -641,9 +641,9 @@ export class chatgpt extends plugin {
if (!bingToken) {
throw new Error('未绑定Bing Cookie请使用#chatgpt设置必应token命令绑定Bing Cookie')
}
let cookie
let cookies
if (bingToken?.indexOf('=') > -1) {
cookie = bingToken
cookies = bingToken
}
let bingAIClient
if (Config.toneStyle === 'Sydney') {
@ -653,10 +653,11 @@ export class chatgpt extends plugin {
}
bingAIClient = new SydneyAIClient({
userToken: bingToken, // "_U" cookie from bing.com
cookie,
cookies,
debug: Config.debug,
cache: cacheOptions,
user: e.sender.user_id
user: e.sender.user_id,
proxy: Config.proxy
})
// Sydney不实现上下文传递删除上下文索引
delete conversation.clientId
@ -665,8 +666,9 @@ export class chatgpt extends plugin {
} else {
bingAIClient = new BingAIClient({
userToken: bingToken, // "_U" cookie from bing.com
cookie,
debug: Config.debug
cookies,
debug: Config.debug,
proxy: Config.proxy
})
}
let response

View file

@ -52,17 +52,20 @@ export default class SydneyAIClient {
host: opts.host || 'https://www.bing.com'
}
this.debug = opts.debug
const cacheOptions = opts.cache || {}
cacheOptions.namespace = cacheOptions.namespace || 'bing'
let _this = this
getKeyv().then(Keyv => {
_this.conversationsCache = new Keyv(cacheOptions)
}).catch(err => {
logger.err(err)
})
}
async initCache () {
if (!this.conversationsCache) {
const cacheOptions = this.opts.cache || {}
cacheOptions.namespace = cacheOptions.namespace || 'bing'
let Keyv = await getKeyv()
this.conversationsCache = new Keyv(cacheOptions)
}
}
async createNewConversation () {
await this.initCache()
console.log(this.opts)
const fetchOptions = {
headers: {
accept: 'application/json',
@ -87,6 +90,7 @@ export default class SydneyAIClient {
'Referrer-Policy': 'origin-when-cross-origin'
}
}
console.log(fetchOptions)
if (this.opts.proxy) {
fetchOptions.dispatcher = new ProxyAgent(this.opts.proxy)
}
@ -95,6 +99,7 @@ export default class SydneyAIClient {
}
async createWebSocketConnection () {
await this.initCache()
let WebSocket = await getWebSocket()
return new Promise((resolve) => {
let agent
@ -160,6 +165,7 @@ export default class SydneyAIClient {
message,
opts = {}
) {
await this.initCache()
if (!this.conversationsCache) {
throw new Error('no support conversationsCache')
}

View file

@ -10,7 +10,7 @@ if (Config.proxy) {
console.warn('未安装https-proxy-agent请在插件目录下执行pnpm add https-proxy-agent')
}
}
function getProxy() {
function getProxy () {
if (proxy) {
return proxy
} else {