mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +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
|
||||
}
|
||||
|
||||
async sendMessage (prompt, opts = {}) {
|
||||
async sendMessage (prompt, opts = {}, retry = 3) {
|
||||
if (retry < 0) {
|
||||
throw new Error('retry limit exceeded')
|
||||
}
|
||||
let {
|
||||
conversationId,
|
||||
parentMessageId = uuidv4(),
|
||||
|
|
@ -143,17 +146,22 @@ export class OfficialChatGPTClient {
|
|||
req.write(JSON.stringify(body))
|
||||
req.end()
|
||||
})
|
||||
const response = await requestP
|
||||
if (statusCode === 200) {
|
||||
return {
|
||||
text: response.response,
|
||||
conversationId: response.conversationId,
|
||||
id: response.messageId,
|
||||
parentMessageId
|
||||
try {
|
||||
const response = await requestP
|
||||
if (statusCode === 200) {
|
||||
return {
|
||||
text: response.response,
|
||||
conversationId: response.conversationId,
|
||||
id: response.messageId,
|
||||
parentMessageId
|
||||
}
|
||||
} else {
|
||||
console.log(response)
|
||||
throw new Error(response)
|
||||
}
|
||||
} else {
|
||||
console.log(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