mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: add retry for api3
This commit is contained in:
parent
a507c85cf8
commit
b76d33d938
2 changed files with 19 additions and 11 deletions
0
client/OpenAILikeClient.js
Normal file
0
client/OpenAILikeClient.js
Normal file
|
|
@ -15,7 +15,10 @@ export class OfficialChatGPTClient {
|
||||||
this._apiReverseUrl = apiReverseUrl
|
this._apiReverseUrl = apiReverseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMessage (prompt, opts = {}) {
|
async sendMessage (prompt, opts = {}, retry = 3) {
|
||||||
|
if (retry < 0) {
|
||||||
|
throw new Error('retry limit exceeded')
|
||||||
|
}
|
||||||
let {
|
let {
|
||||||
conversationId,
|
conversationId,
|
||||||
parentMessageId = uuidv4(),
|
parentMessageId = uuidv4(),
|
||||||
|
|
@ -143,6 +146,7 @@ export class OfficialChatGPTClient {
|
||||||
req.write(JSON.stringify(body))
|
req.write(JSON.stringify(body))
|
||||||
req.end()
|
req.end()
|
||||||
})
|
})
|
||||||
|
try {
|
||||||
const response = await requestP
|
const response = await requestP
|
||||||
if (statusCode === 200) {
|
if (statusCode === 200) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -155,5 +159,9 @@ export class OfficialChatGPTClient {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
throw new Error(response)
|
throw new Error(response)
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn(err)
|
||||||
|
return await this.sendMessage(prompt, opts, retry - 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue