mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: 修复sydney 502错误未被catch到的问题
This commit is contained in:
parent
7df0a3eb10
commit
85809385c8
2 changed files with 10 additions and 19 deletions
|
|
@ -122,26 +122,16 @@ export default class SydneyAIClient {
|
||||||
async createWebSocketConnection () {
|
async createWebSocketConnection () {
|
||||||
await this.initCache()
|
await this.initCache()
|
||||||
let WebSocket = await getWebSocket()
|
let WebSocket = await getWebSocket()
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
let agent
|
let agent
|
||||||
if (this.opts.proxy) {
|
if (this.opts.proxy) {
|
||||||
agent = new HttpsProxyAgent(this.opts.proxy)
|
agent = new HttpsProxyAgent(this.opts.proxy)
|
||||||
}
|
}
|
||||||
let retryTimes = 3
|
let ws = new WebSocket('wss://sydney.bing.com/sydney/ChatHub', { agent })
|
||||||
let ws
|
|
||||||
do {
|
ws.on('error', (err) => {
|
||||||
try {
|
reject(err)
|
||||||
ws = new WebSocket('wss://sydney.bing.com/sydney/ChatHub', { agent })
|
})
|
||||||
break
|
|
||||||
} catch (err) {
|
|
||||||
logger.warn(err)
|
|
||||||
retryTimes--
|
|
||||||
if (retryTimes === 0) {
|
|
||||||
throw new Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (retryTimes > 0)
|
|
||||||
ws.on('error', console.error)
|
|
||||||
|
|
||||||
ws.on('open', () => {
|
ws.on('open', () => {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
|
|
@ -410,6 +400,7 @@ export default class SydneyAIClient {
|
||||||
const event = events[0]
|
const event = events[0]
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 1: {
|
case 1: {
|
||||||
|
// reject(new Error('test'))
|
||||||
if (stopTokenFound || apology) {
|
if (stopTokenFound || apology) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -472,8 +463,8 @@ export default class SydneyAIClient {
|
||||||
}
|
}
|
||||||
const messages = event.item?.messages || []
|
const messages = event.item?.messages || []
|
||||||
const message = messages.length
|
const message = messages.length
|
||||||
? messages[messages.length - 1]
|
? messages[messages.length - 1]
|
||||||
: {
|
: {
|
||||||
adaptiveCards: [
|
adaptiveCards: [
|
||||||
{
|
{
|
||||||
body: [
|
body: [
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ const defaultConfig = {
|
||||||
noiseScaleW: 0.668,
|
noiseScaleW: 0.668,
|
||||||
lengthScale: 1.2,
|
lengthScale: 1.2,
|
||||||
initiativeChatGroups: [],
|
initiativeChatGroups: [],
|
||||||
version: 'v2.1.2'
|
version: 'v2.1.3'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
let config = {}
|
let config = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue