mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: no support cache
This commit is contained in:
parent
90c7c992a6
commit
5ceb9c9de3
3 changed files with 23 additions and 15 deletions
|
|
@ -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')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue