mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: 超时时,如果已经有部分回复则返回这部分回复
This commit is contained in:
parent
b332170a1d
commit
de5707de2b
1 changed files with 17 additions and 4 deletions
|
|
@ -181,7 +181,8 @@ export default class SydneyAIClient {
|
||||||
invocationId = 0,
|
invocationId = 0,
|
||||||
parentMessageId = invocationId || crypto.randomUUID(),
|
parentMessageId = invocationId || crypto.randomUUID(),
|
||||||
onProgress,
|
onProgress,
|
||||||
abortController = new AbortController()
|
abortController = new AbortController(),
|
||||||
|
timeout = Config.defaultTimeoutMs
|
||||||
} = opts
|
} = opts
|
||||||
if (typeof onProgress !== 'function') {
|
if (typeof onProgress !== 'function') {
|
||||||
onProgress = () => {}
|
onProgress = () => {}
|
||||||
|
|
@ -314,14 +315,26 @@ export default class SydneyAIClient {
|
||||||
|
|
||||||
const messageTimeout = setTimeout(() => {
|
const messageTimeout = setTimeout(() => {
|
||||||
this.cleanupWebSocketConnection(ws)
|
this.cleanupWebSocketConnection(ws)
|
||||||
|
if (replySoFar) {
|
||||||
|
resolve({
|
||||||
|
message
|
||||||
|
})
|
||||||
|
} else {
|
||||||
reject(new Error('Timed out waiting for response. Try enabling debug mode to see more information.'))
|
reject(new Error('Timed out waiting for response. Try enabling debug mode to see more information.'))
|
||||||
}, 120 * 1000)
|
}
|
||||||
|
}, timeout)
|
||||||
|
|
||||||
// abort the request if the abort controller is aborted
|
// abort the request if the abort controller is aborted
|
||||||
abortController.signal.addEventListener('abort', () => {
|
abortController.signal.addEventListener('abort', () => {
|
||||||
clearTimeout(messageTimeout)
|
clearTimeout(messageTimeout)
|
||||||
this.cleanupWebSocketConnection(ws)
|
this.cleanupWebSocketConnection(ws)
|
||||||
|
if (replySoFar) {
|
||||||
|
resolve({
|
||||||
|
message
|
||||||
|
})
|
||||||
|
} else {
|
||||||
reject('Request aborted')
|
reject('Request aborted')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
ws.on('message', (data) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue