mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
feat: bym
This commit is contained in:
parent
6997d1e024
commit
9fcc25a726
5 changed files with 219 additions and 46 deletions
25
apps/chat.js
25
apps/chat.js
|
|
@ -1,6 +1,6 @@
|
|||
import Config from '../config/config.js'
|
||||
import { Chaite, SendMessageOption } from 'chaite'
|
||||
import { getPreset, intoUserMessage } from '../utils/message.js'
|
||||
import { getPreset, intoUserMessage, toYunzai } from '../utils/message.js'
|
||||
|
||||
export class Chat extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -22,9 +22,18 @@ export class Chat extends plugin {
|
|||
async chat (e) {
|
||||
const state = await Chaite.getInstance().getUserStateStorage().getItem(e.sender.user_id + '')
|
||||
const sendMessageOptions = SendMessageOption.create(state?.settings)
|
||||
sendMessageOptions.onMessageWithToolCall = async content => {
|
||||
const { msgs, forward } = await toYunzai(e, [content])
|
||||
if (msgs.length > 0) {
|
||||
await e.reply(msgs)
|
||||
}
|
||||
for (let forwardElement of forward) {
|
||||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
const preset = await getPreset(e, state?.settings.preset || Config.llm.defaultChatPresetId, Config.basic.toggleMode, Config.basic.togglePrefix)
|
||||
if (!preset) {
|
||||
logger.debug('未找到预设,不进入对话')
|
||||
logger.debug('不满足对话触发条件或未找到预设,不进入对话')
|
||||
return false
|
||||
}
|
||||
const userMessage = await intoUserMessage(e, {
|
||||
|
|
@ -40,10 +49,12 @@ export class Chat extends plugin {
|
|||
...sendMessageOptions,
|
||||
chatPreset: preset
|
||||
})
|
||||
const responseText = response.contents
|
||||
.filter(c => c.type === 'text')
|
||||
.map(c => (/** @type {import('chaite').TextContent} **/ c).text)
|
||||
.reduce((a, b) => a + b, '')
|
||||
await this.reply(responseText)
|
||||
const { msgs, forward } = await toYunzai(e, response.contents)
|
||||
if (msgs.length > 0) {
|
||||
await e.reply(msgs, true)
|
||||
}
|
||||
for (let forwardElement of forward) {
|
||||
this.reply(forwardElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue