fix: sydney模式支持proxy

This commit is contained in:
ikechan8370 2023-03-04 12:23:58 +08:00
parent 5ceb9c9de3
commit 1edfe81794

View file

@ -20,6 +20,14 @@ try {
} catch (error) {
logger.warn('【ChatGPT-Plugin】依赖ws未安装可能影响Sydney模式下Bing对话建议使用pnpm install ws安装')
}
let proxy
if (Config.proxy) {
try {
proxy = (await import('https-proxy-agent')).default
} catch (e) {
console.warn('未安装https-proxy-agent请在插件目录下执行pnpm add https-proxy-agent')
}
}
async function getWebSocket () {
let WebSocket
try {
@ -92,7 +100,7 @@ export default class SydneyAIClient {
}
console.log(fetchOptions)
if (this.opts.proxy) {
fetchOptions.dispatcher = new ProxyAgent(this.opts.proxy)
fetchOptions.agent = proxy(Config.proxy)
}
const response = await fetch(`${this.opts.host}/turing/conversation/create`, fetchOptions)
return response.json()
@ -178,7 +186,6 @@ export default class SydneyAIClient {
onProgress,
abortController = new AbortController()
} = opts
if (typeof onProgress !== 'function') {
onProgress = () => {}
}