mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-15 12:57:10 +00:00
fix: 修改群聊提示词
This commit is contained in:
parent
b30488bdb9
commit
85d61ea210
4 changed files with 37 additions and 21 deletions
|
|
@ -15,6 +15,13 @@
|
|||
|
||||
|
||||
> 插件v3大幅重构中,[核心](https://github.com/ikechan8370/node-chaite)已完成,插件基本功能可用,持续完善中。
|
||||
> todo列表:
|
||||
> - [x] 插件v3重构完成,插件基本功能可用,持续完善中。
|
||||
> - [ ] RAG知识库
|
||||
> - [ ] 预设更详细的配置
|
||||
> - [ ] 自定义触发器
|
||||
> - [ ] 自定义插件
|
||||
> - [ ] 兼容mcp
|
||||
|
||||
|
||||
## 赞助
|
||||
|
|
|
|||
|
|
@ -94,16 +94,16 @@ export class ChatGPTManagement extends plugin {
|
|||
return false
|
||||
}
|
||||
const userStates = await Chaite.getInstance().getUserStateStorage().listItems()
|
||||
let num = 0
|
||||
// let num = 0
|
||||
for (const userState of userStates) {
|
||||
if (userState.current.conversationId && userState.current.messageId) {
|
||||
num++
|
||||
// num++
|
||||
userState.current.conversationId = crypto.randomUUID()
|
||||
userState.current.messageId = crypto.randomUUID()
|
||||
await Chaite.getInstance().getUserStateStorage().setItem(userState.userId + '', userState)
|
||||
}
|
||||
}
|
||||
this.reply(`已结束${num}个用户的对话`)
|
||||
this.reply('已结束全部对话')
|
||||
} else {
|
||||
const state = await Chaite.getInstance().getUserStateStorage().getItem(e.sender.user_id + '')
|
||||
if (!state || !state.current.conversationId || !state.current.messageId) {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,10 @@ class ChatGPTConfig {
|
|||
// 群组上下文长度
|
||||
groupContextLength: 20,
|
||||
// 用于组装群聊上下文提示词的模板前缀
|
||||
groupContextTemplatePrefix: 'Latest several messages in the group chat:\n' +
|
||||
groupContextTemplatePrefix: '<settings>\n' +
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
'You are a member of a chat group, whose name is ${group.name}, and the group id is ${group.id}.\n' +
|
||||
'</settings>Latest several messages in the group chat:\n' +
|
||||
'| 群名片 | 昵称 | qq号 | 群角色 | 群头衔 | 时间 | messageId | 消息内容 |\n' +
|
||||
'|---|---|---|---|---|---|---|---|',
|
||||
// 用于组装群聊上下文提示词的模板内容部分,每一条消息作为message,仿照示例填写
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { getBotFramework } from './bot.js'
|
||||
import ChatGPTConfig from '../config/config.js'
|
||||
import {formatTimeToBeiJing} from './common.js'
|
||||
import { formatTimeToBeiJing } from './common.js'
|
||||
|
||||
export class GroupContextCollector {
|
||||
/**
|
||||
|
|
@ -114,33 +114,39 @@ export async function getGroupHistory (e, length = 20) {
|
|||
*/
|
||||
export async function getGroupContextPrompt (e, length) {
|
||||
const {
|
||||
groupContextTemplatePrefix,
|
||||
groupContextTemplateMessage,
|
||||
groupContextTemplateSuffix
|
||||
groupContextTemplatePrefix = '',
|
||||
groupContextTemplateMessage = '',
|
||||
groupContextTemplateSuffix = ''
|
||||
} = ChatGPTConfig.llm
|
||||
const chats = await getGroupHistory(e, length)
|
||||
const rows = chats.map(chat => {
|
||||
const sender = chat.sender || {}
|
||||
return groupContextTemplateMessage
|
||||
const rows = chats
|
||||
.filter(chat => chat)
|
||||
.map(chat => {
|
||||
const sender = chat.sender || {}
|
||||
return groupContextTemplateMessage
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.card}', sender.card || '-')
|
||||
.replace('${message.sender.card}', sender.card || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.nickname}', sender.nickname || '-')
|
||||
.replace('${message.sender.nickname}', sender.nickname || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.user_id}', sender.user_id || '-')
|
||||
.replace('${message.sender.user_id}', sender.user_id || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.role}', sender.role || '-')
|
||||
.replace('${message.sender.role}', sender.role || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.title}', sender.title || '-')
|
||||
.replace('${message.sender.title}', sender.title || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.time}', chat.time ? formatTimeToBeiJing(chat.time) : '-')
|
||||
.replace('${message.time}', chat.time ? formatTimeToBeiJing(chat.time) : '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.messageId}', chat.messageId || '-')
|
||||
.replace('${message.messageId}', chat.messageId || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.raw_message}', chat.raw_message || '-')
|
||||
}).join('\n')
|
||||
.replace('${message.raw_message}', chat.raw_message || '-')
|
||||
}).join('\n')
|
||||
return [
|
||||
groupContextTemplatePrefix,
|
||||
groupContextTemplatePrefix
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${group.group_id}', e.group.group_id || e.group_id || 'unknown')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${group.name}', e.group.name || e.group_name || 'unknown'),
|
||||
rows,
|
||||
groupContextTemplateSuffix
|
||||
].join('\n')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue