mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
feat: api模式下,字数超限自动重置对话
This commit is contained in:
parent
db649632bc
commit
c11732be4c
1 changed files with 17 additions and 1 deletions
18
apps/chat.js
18
apps/chat.js
|
|
@ -574,6 +574,10 @@ export class chatgpt extends plugin {
|
||||||
logger.mark({ conversation })
|
logger.mark({ conversation })
|
||||||
}
|
}
|
||||||
let chatMessage = await this.sendMessage(prompt, conversation, use, e)
|
let chatMessage = await this.sendMessage(prompt, conversation, use, e)
|
||||||
|
if (use === 'api' && !chatMessage) {
|
||||||
|
// 字数超限直接返回
|
||||||
|
return false
|
||||||
|
}
|
||||||
if (use !== 'api3') {
|
if (use !== 'api3') {
|
||||||
previousConversation.conversation = {
|
previousConversation.conversation = {
|
||||||
conversationId: chatMessage.conversationId
|
conversationId: chatMessage.conversationId
|
||||||
|
|
@ -837,7 +841,19 @@ export class chatgpt extends plugin {
|
||||||
if (conversation) {
|
if (conversation) {
|
||||||
option = Object.assign(option, conversation)
|
option = Object.assign(option, conversation)
|
||||||
}
|
}
|
||||||
return await tryTimes(async () => await this.chatGPTApi.sendMessage(prompt, option), 1)
|
let msg
|
||||||
|
try {
|
||||||
|
msg = await this.chatGPTApi.sendMessage(prompt, option)
|
||||||
|
} catch (err) {
|
||||||
|
if (err.message?.indexOf('context_length_exceeded')) {
|
||||||
|
await redis.del(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
|
||||||
|
await e.reply('字数超限啦,将为您自动结束本次对话。')
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
throw new Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue