mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-18 14:27:10 +00:00
fix: 会话连续问题
This commit is contained in:
parent
89dd029d0e
commit
e5e26bc4d1
1 changed files with 20 additions and 9 deletions
29
apps/chat.js
29
apps/chat.js
|
|
@ -191,11 +191,11 @@ export class chatgpt extends plugin {
|
||||||
let question = e.msg.trimStart()
|
let question = e.msg.trimStart()
|
||||||
await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 5 })
|
await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 5 })
|
||||||
logger.info(`chatgpt question: ${question}`)
|
logger.info(`chatgpt question: ${question}`)
|
||||||
try {
|
// try {
|
||||||
await this.chatGPTApi.init()
|
// await this.chatGPTApi.init()
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
await this.reply('chatgpt初始化出错:' + e.msg, true)
|
// await this.reply('chatgpt初始化出错:' + e.msg, true)
|
||||||
}
|
// }
|
||||||
let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
|
let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
|
||||||
let conversation = null
|
let conversation = null
|
||||||
if (!previousConversation) {
|
if (!previousConversation) {
|
||||||
|
|
@ -217,12 +217,11 @@ export class chatgpt extends plugin {
|
||||||
try {
|
try {
|
||||||
let option = {
|
let option = {
|
||||||
onConversationResponse: function (c) {
|
onConversationResponse: function (c) {
|
||||||
let pc = _.clone(previousConversation)
|
previousConversation.conversation = {
|
||||||
pc.conversation = {
|
|
||||||
conversationId: c.conversation_id,
|
conversationId: c.conversation_id,
|
||||||
parentMessageId: c.message.id
|
parentMessageId: c.message.id
|
||||||
}
|
}
|
||||||
redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(pc), { EX: CONVERSATION_PRESERVE_TIME }).then(res => {
|
redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(previousConversation), { EX: CONVERSATION_PRESERVE_TIME }).then(res => {
|
||||||
logger.debug('redis set conversation')
|
logger.debug('redis set conversation')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +251,19 @@ export class chatgpt extends plugin {
|
||||||
// !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith(']') && !response.trimEnd().endsWith('】')
|
// !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith(']') && !response.trimEnd().endsWith('】')
|
||||||
// ) {
|
// ) {
|
||||||
await this.reply('内容有点多,我正在奋笔疾书,请再等一会', true, { recallMsg: 5 })
|
await this.reply('内容有点多,我正在奋笔疾书,请再等一会', true, { recallMsg: 5 })
|
||||||
const responseAppend = await this.chatGPTApi.sendMessage('Continue')
|
option = {
|
||||||
|
onConversationResponse: function (c) {
|
||||||
|
previousConversation.conversation = {
|
||||||
|
conversationId: c.conversation_id,
|
||||||
|
parentMessageId: c.message.id
|
||||||
|
}
|
||||||
|
redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(previousConversation), { EX: CONVERSATION_PRESERVE_TIME }).then(res => {
|
||||||
|
logger.debug('redis set conversation')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
option = Object.assign(option, previousConversation.conversation)
|
||||||
|
const responseAppend = await this.chatGPTApi.sendMessage('Continue', option)
|
||||||
// console.log(responseAppend)
|
// console.log(responseAppend)
|
||||||
// 检索是否有屏蔽词
|
// 检索是否有屏蔽词
|
||||||
const blockWord = blockWords.split(',').find(word => responseAppend.toLowerCase().includes(word.toLowerCase()))
|
const blockWord = blockWords.split(',').find(word => responseAppend.toLowerCase().includes(word.toLowerCase()))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue