mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: api3 gpt-4o
This commit is contained in:
parent
d82320d04c
commit
21485df0aa
1 changed files with 12 additions and 6 deletions
|
|
@ -15,21 +15,23 @@ export class OfficialChatGPTClient {
|
||||||
this._apiReverseUrl = apiReverseUrl
|
this._apiReverseUrl = apiReverseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMessage (prompt, opts = {}, retry = 3) {
|
async sendMessage (prompt, opts = {}, retry = 3, errorMsg) {
|
||||||
if (retry < 0) {
|
if (retry < 0) {
|
||||||
throw new Error('retry limit exceeded')
|
throw new Error(errorMsg || 'retry limit exceeded')
|
||||||
}
|
}
|
||||||
let {
|
let {
|
||||||
conversationId,
|
conversationId,
|
||||||
parentMessageId = uuidv4(),
|
parentMessageId = uuidv4(),
|
||||||
messageId = uuidv4(),
|
messageId = uuidv4(),
|
||||||
action = 'next'
|
action = 'next',
|
||||||
|
model = ''
|
||||||
} = opts
|
} = opts
|
||||||
let url = this._apiReverseUrl || officialChatGPTAPI
|
let url = this._apiReverseUrl || officialChatGPTAPI
|
||||||
if (this._apiReverseUrl && Config.proxy && !Config.apiForceUseReverse) {
|
if (this._apiReverseUrl && Config.proxy && !Config.apiForceUseReverse) {
|
||||||
// 如果配了proxy,而且有反代,但是没开启强制反代
|
// 如果配了proxy,而且有反代,但是没开启强制反代
|
||||||
url = officialChatGPTAPI
|
url = officialChatGPTAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
action,
|
action,
|
||||||
messages: [
|
messages: [
|
||||||
|
|
@ -43,7 +45,7 @@ export class OfficialChatGPTClient {
|
||||||
metadata: {}
|
metadata: {}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
model: 'auto',
|
model: model || (Config.useGPT4 ? 'gpt-4o' : 'auto'),
|
||||||
parent_message_id: parentMessageId,
|
parent_message_id: parentMessageId,
|
||||||
timezone_offset_min: -480,
|
timezone_offset_min: -480,
|
||||||
history_and_training_disabled: false
|
history_and_training_disabled: false
|
||||||
|
|
@ -157,11 +159,15 @@ export class OfficialChatGPTClient {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
throw new Error(response)
|
throw new Error(JSON.stringify(response))
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(err)
|
logger.warn(err)
|
||||||
return await this.sendMessage(prompt, opts, retry - 1)
|
if (err.message?.includes('You have sent too many messages to the model. Please try again later.')) {
|
||||||
|
logger.warn('账户的gpt-o额度不足,将降级为auto重试')
|
||||||
|
opts.model = 'auto'
|
||||||
|
}
|
||||||
|
return await this.sendMessage(prompt, opts, retry - 1, err.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue