mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 05:17:10 +00:00
fix: 调试设定和伪人
This commit is contained in:
parent
efb5a8f174
commit
3c77da5373
11 changed files with 293 additions and 34 deletions
28
apps/bym.js
28
apps/bym.js
|
|
@ -2,6 +2,7 @@ import ChatGPTConfig from '../config/config.js'
|
|||
import { Chaite } from 'chaite'
|
||||
import { intoUserMessage, toYunzai } from '../utils/message.js'
|
||||
import common from '../../../lib/common/common.js'
|
||||
import { getGroupContextPrompt } from '../utils/group.js'
|
||||
|
||||
export class bym extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -9,11 +10,12 @@ export class bym extends plugin {
|
|||
name: 'ChatGPT-Plugin伪人模式',
|
||||
dsc: 'ChatGPT-Plugin伪人模式',
|
||||
event: 'message',
|
||||
priority: -150,
|
||||
priority: 6000,
|
||||
rule: [
|
||||
{
|
||||
reg: '^#chatgpt伪人模式$',
|
||||
fnc: 'bym'
|
||||
reg: '^[^#][sS]*',
|
||||
fnc: 'bym',
|
||||
log: false
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -23,11 +25,19 @@ export class bym extends plugin {
|
|||
if (!ChatGPTConfig.bym.enable) {
|
||||
return false
|
||||
}
|
||||
let prob = ChatGPTConfig.bym.probability
|
||||
if (ChatGPTConfig.bym.hit.find(keyword => e.msg?.includes(keyword))) {
|
||||
prob = 1
|
||||
}
|
||||
if (Math.random() > prob) {
|
||||
return false
|
||||
}
|
||||
logger.info('伪人模式触发')
|
||||
let recall = false
|
||||
let presetId = ChatGPTConfig.bym.defaultPreset
|
||||
if (ChatGPTConfig.bym.presetMap && ChatGPTConfig.bym.presetMap.length > 0) {
|
||||
const option = ChatGPTConfig.bym.presetMap.sort((a, b) => a.priority - b.priority)
|
||||
.find(item => item.keywords.find(keyword => e.msg.includes(keyword)))
|
||||
.find(item => item.keywords.find(keyword => e.msg?.includes(keyword)))
|
||||
if (option) {
|
||||
presetId = option.presetId
|
||||
}
|
||||
|
|
@ -49,6 +59,12 @@ export class bym extends plugin {
|
|||
}
|
||||
preset.sendMessageOption.systemOverride = ChatGPTConfig.bym.presetPrefix + preset.sendMessageOption.systemOverride
|
||||
}
|
||||
if (ChatGPTConfig.bym.temperature >= 0) {
|
||||
preset.sendMessageOption.temperature = ChatGPTConfig.bym.temperature
|
||||
}
|
||||
if (ChatGPTConfig.bym.maxTokens > 0) {
|
||||
preset.sendMessageOption.maxTokens = ChatGPTConfig.bym.maxTokens
|
||||
}
|
||||
const userMessage = await intoUserMessage(e, {
|
||||
handleReplyText: true,
|
||||
handleReplyImage: true,
|
||||
|
|
@ -71,6 +87,10 @@ export class bym extends plugin {
|
|||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
if (ChatGPTConfig.llm.enableGroupContext && e.isGroup) {
|
||||
const contextPrompt = await getGroupContextPrompt(e, ChatGPTConfig.llm.groupContextLength)
|
||||
preset.sendMessageOption.systemOverride = preset.sendMessageOption.systemOverride ? preset.sendMessageOption.systemOverride + '\n' + contextPrompt : contextPrompt
|
||||
}
|
||||
// 发送
|
||||
const response = await Chaite.getInstance().sendMessage(userMessage, e, {
|
||||
...preset.sendMessageOption,
|
||||
|
|
|
|||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import ChatGPTConfig from '../config/config.js'
|
||||
import { createCRUDCommandRules, createSwitchCommandRules } from '../utils/command.js'
|
||||
import { Chaite } from 'chaite'
|
||||
import * as crypto from 'node:crypto'
|
||||
|
||||
export class ChatGPTManagement extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -17,7 +18,7 @@ export class ChatGPTManagement extends plugin {
|
|||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: `^${cmdPrefix}结束(全部)?对话$`,
|
||||
reg: `^(${cmdPrefix})?#?结束(全部)?对话$`,
|
||||
fnc: 'destroyConversation'
|
||||
},
|
||||
{
|
||||
|
|
@ -27,18 +28,22 @@ export class ChatGPTManagement extends plugin {
|
|||
}
|
||||
]
|
||||
})
|
||||
this.initCommand(cmdPrefix)
|
||||
if (!Chaite.getInstance()) {
|
||||
const waitForChaite = async () => {
|
||||
while (!Chaite.getInstance()) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
return Chaite.getInstance()
|
||||
}
|
||||
waitForChaite().then(() => {
|
||||
this.initCommand(cmdPrefix)
|
||||
})
|
||||
} else {
|
||||
this.initCommand(cmdPrefix)
|
||||
}
|
||||
}
|
||||
|
||||
async initCommand (cmdPrefix) {
|
||||
const waitForChaite = async () => {
|
||||
while (!Chaite.getInstance()) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
return Chaite.getInstance()
|
||||
}
|
||||
|
||||
await waitForChaite()
|
||||
initCommand (cmdPrefix) {
|
||||
this.rule.push(...[
|
||||
...createCRUDCommandRules.bind(this)(cmdPrefix, '渠道', 'channels'),
|
||||
...createCRUDCommandRules.bind(this)(cmdPrefix, '预设', 'presets'),
|
||||
|
|
@ -94,7 +99,11 @@ export class ChatGPTManagement extends plugin {
|
|||
this.reply(`已结束${num}个用户的对话`)
|
||||
} else {
|
||||
const state = await Chaite.getInstance().getUserStateStorage().getItem(e.sender.user_id + '')
|
||||
state.current.conversationId = ''
|
||||
if (!state) {
|
||||
this.reply('当前未开启对话')
|
||||
return false
|
||||
}
|
||||
state.current.conversationId = crypto.randomUUID()
|
||||
state.current.messageId = ''
|
||||
await Chaite.getInstance().getUserStateStorage().setItem(e.sender.user_id + '', state)
|
||||
this.reply('已结束当前对话')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue