mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: memory cursor and extract prompt
This commit is contained in:
parent
660de1b462
commit
0550e6d492
7 changed files with 257 additions and 48 deletions
23
apps/bym.js
23
apps/bym.js
|
|
@ -5,6 +5,7 @@ import common from '../../../lib/common/common.js'
|
|||
import { getGroupContextPrompt } from '../utils/group.js'
|
||||
import { formatTimeToBeiJing } from '../utils/common.js'
|
||||
import { extractTextFromUserMessage, processUserMemory } from '../models/memory/userMemoryManager.js'
|
||||
import { buildMemoryPrompt } from '../models/memory/prompt.js'
|
||||
|
||||
export class bym extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -100,9 +101,29 @@ export class bym extends plugin {
|
|||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
const systemSegments = []
|
||||
if (sendMessageOption.systemOverride) {
|
||||
systemSegments.push(sendMessageOption.systemOverride)
|
||||
}
|
||||
if (userText) {
|
||||
const memoryPrompt = await buildMemoryPrompt({
|
||||
userId: e.sender.user_id + '',
|
||||
groupId: e.isGroup ? e.group_id + '' : null,
|
||||
queryText: userText
|
||||
})
|
||||
if (memoryPrompt) {
|
||||
systemSegments.push(memoryPrompt)
|
||||
logger.debug(`[Memory] bym memory prompt: ${memoryPrompt}`)
|
||||
}
|
||||
}
|
||||
if (ChatGPTConfig.llm.enableGroupContext && e.isGroup) {
|
||||
const contextPrompt = await getGroupContextPrompt(e, ChatGPTConfig.llm.groupContextLength)
|
||||
sendMessageOption.systemOverride = sendMessageOption.systemOverride ? sendMessageOption.systemOverride + '\n' + contextPrompt : contextPrompt
|
||||
if (contextPrompt) {
|
||||
systemSegments.push(contextPrompt)
|
||||
}
|
||||
}
|
||||
if (systemSegments.length > 0) {
|
||||
sendMessageOption.systemOverride = systemSegments.join('\n\n')
|
||||
}
|
||||
// 发送
|
||||
const response = await Chaite.getInstance().sendMessage(userMessage, e, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue