mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 调试设定和伪人
This commit is contained in:
parent
efb5a8f174
commit
3c77da5373
11 changed files with 293 additions and 34 deletions
38
apps/chat.js
38
apps/chat.js
|
|
@ -1,6 +1,8 @@
|
|||
import Config from '../config/config.js'
|
||||
import { Chaite, SendMessageOption } from 'chaite'
|
||||
import { getPreset, intoUserMessage, toYunzai } from '../utils/message.js'
|
||||
import { YunzaiUserState } from '../models/chaite/user_state_storage.js'
|
||||
import { getGroupContextPrompt, getGroupHistory } from '../utils/group.js'
|
||||
|
||||
export class Chat extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -8,19 +10,34 @@ export class Chat extends plugin {
|
|||
name: 'ChatGPT-Plugin对话',
|
||||
dsc: 'ChatGPT-Plugin对话',
|
||||
event: 'message',
|
||||
priority: 0,
|
||||
priority: 500,
|
||||
rule: [
|
||||
{
|
||||
reg: '^[^#][sS]*',
|
||||
fnc: 'chat',
|
||||
log: false
|
||||
},
|
||||
{
|
||||
reg: '#hi',
|
||||
fnc: 'history'
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
async chat (e) {
|
||||
const state = await Chaite.getInstance().getUserStateStorage().getItem(e.sender.user_id + '')
|
||||
let state = await Chaite.getInstance().getUserStateStorage().getItem(e.sender.user_id + '')
|
||||
if (!state) {
|
||||
state = new YunzaiUserState(e.sender.user_id, e.sender.nickname, e.sender.card)
|
||||
await Chaite.getInstance().getUserStateStorage().setItem(e.sender.user_id + '', state)
|
||||
}
|
||||
const preset = await getPreset(e, state?.settings.preset || Config.llm.defaultChatPresetId, Config.basic.toggleMode, Config.basic.togglePrefix)
|
||||
if (!preset) {
|
||||
logger.debug('不满足对话触发条件或未找到预设,不进入对话')
|
||||
return false
|
||||
} else {
|
||||
logger.info('进入对话, prompt: ' + e.msg)
|
||||
}
|
||||
const sendMessageOptions = SendMessageOption.create(state?.settings)
|
||||
sendMessageOptions.onMessageWithToolCall = async content => {
|
||||
const { msgs, forward } = await toYunzai(e, [content])
|
||||
|
|
@ -31,11 +48,6 @@ export class Chat extends plugin {
|
|||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
const preset = await getPreset(e, state?.settings.preset || Config.llm.defaultChatPresetId, Config.basic.toggleMode, Config.basic.togglePrefix)
|
||||
if (!preset) {
|
||||
logger.debug('不满足对话触发条件或未找到预设,不进入对话')
|
||||
return false
|
||||
}
|
||||
const userMessage = await intoUserMessage(e, {
|
||||
handleReplyText: false,
|
||||
handleReplyImage: true,
|
||||
|
|
@ -45,10 +57,17 @@ export class Chat extends plugin {
|
|||
toggleMode: Config.basic.toggleMode,
|
||||
togglePrefix: Config.basic.togglePrefix
|
||||
})
|
||||
if (Config.llm.enableGroupContext && e.isGroup) {
|
||||
const contextPrompt = await getGroupContextPrompt(e, Config.llm.groupContextLength)
|
||||
sendMessageOptions.systemOverride = sendMessageOptions.systemOverride ? sendMessageOptions.systemOverride + '\n' + contextPrompt : (preset.sendMessageOption.systemOverride + contextPrompt)
|
||||
}
|
||||
const response = await Chaite.getInstance().sendMessage(userMessage, e, {
|
||||
...sendMessageOptions,
|
||||
chatPreset: preset
|
||||
})
|
||||
// 更新当前聊天进度
|
||||
state.current.messageId = response.id
|
||||
await Chaite.getInstance().getUserStateStorage().setItem(e.sender.user_id + '', state)
|
||||
const { msgs, forward } = await toYunzai(e, response.contents)
|
||||
if (msgs.length > 0) {
|
||||
await e.reply(msgs, true)
|
||||
|
|
@ -57,4 +76,9 @@ export class Chat extends plugin {
|
|||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
|
||||
async history (e) {
|
||||
const history = await getGroupHistory(e, 10)
|
||||
e.reply(JSON.stringify(history))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue