mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
48518b49c5
5 changed files with 27 additions and 23 deletions
16
apps/bym.js
16
apps/bym.js
|
|
@ -2,8 +2,8 @@ import { Config } from '../utils/config.js'
|
|||
import { getChatHistoryGroup } from '../utils/chat.js'
|
||||
import { convertFaces } from '../utils/face.js'
|
||||
import { customSplitRegex, filterResponseChunk } from '../utils/text.js'
|
||||
import core, {roleMap} from '../model/core.js'
|
||||
import {formatDate} from '../utils/common.js'
|
||||
import core, { roleMap } from '../model/core.js'
|
||||
import { formatDate } from '../utils/common.js'
|
||||
|
||||
export class bym extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -55,15 +55,9 @@ export class bym extends plugin {
|
|||
}
|
||||
if (prop < Config.bymRate) {
|
||||
logger.info('random chat hit')
|
||||
let chats = await getChatHistoryGroup(e, Config.groupContextLength)
|
||||
// let chats = await getChatHistoryGroup(e, Config.groupContextLength)
|
||||
let system = `你的名字是“${Config.assistantLabel}”,你在一个qq群里,群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。如果此时不需要自己说话,可以只回复<EMPTY>` +
|
||||
candidate +
|
||||
'以下是聊天记录:' + chats
|
||||
.map(chat => {
|
||||
let sender = chat.sender || chat || {}
|
||||
return `【${sender.card || sender.nickname}】(qq:${sender.user_id}, ${roleMap[sender.role] || 'normal user'},${sender.area ? 'from ' + sender.area + ', ' : ''} ${sender.age} years old, 群头衔:${sender.title}, gender: ${sender.sex}, time:${formatDate(new Date(chat.time * 1000))} 说:${chat.raw_message}`
|
||||
})
|
||||
.join('\n') +
|
||||
`\n你的回复应该尽可能简练,像人类一样随意,不要附加任何奇怪的东西,如聊天记录的格式(比如${Config.assistantLabel}:),禁止重复聊天记录。`
|
||||
|
||||
let rsp = await core.sendMessage(e.msg, {}, Config.bymMode, e, {
|
||||
|
|
@ -81,7 +75,9 @@ export class bym extends plugin {
|
|||
replyPureTextCallback: msg => {
|
||||
msg = filterResponseChunk(msg)
|
||||
msg && e.reply(msg)
|
||||
}
|
||||
},
|
||||
// 强制打开上下文,不然伪人笨死了
|
||||
enableGroupContext: true
|
||||
}
|
||||
})
|
||||
// let rsp = await client.sendMessage(e.msg, opt)
|
||||
|
|
|
|||
|
|
@ -121,7 +121,9 @@ export class BingAIClient {
|
|||
this.ws.once('message', (data) => {
|
||||
clearTimeout(timeout) // 清除超时定时器
|
||||
const message = JSON.parse(data)
|
||||
logger.info(data)
|
||||
if (this.debug) {
|
||||
logger.info(data)
|
||||
}
|
||||
if (message.event === 'challenge') {
|
||||
logger.warn('遇到turnstile验证码,尝试使用2captcha解决')
|
||||
// 如果收到 challenge,处理挑战
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
|
|||
delete content.conversationId
|
||||
})
|
||||
if (this.debug) {
|
||||
logger.info(JSON.stringify(body))
|
||||
logger.debug(JSON.stringify(body))
|
||||
}
|
||||
let result = await newFetch(url, {
|
||||
method: 'POST',
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ export const roleMap = {
|
|||
|
||||
const defaultPropmtPrefix = ', a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.'
|
||||
|
||||
async function handleSystem (e, system) {
|
||||
if (Config.enableGroupContext) {
|
||||
async function handleSystem (e, system, settings) {
|
||||
if (settings.enableGroupContext) {
|
||||
try {
|
||||
let opt = {}
|
||||
opt.groupId = e.group_id
|
||||
|
|
@ -126,7 +126,8 @@ class Core {
|
|||
xh: Config.xhPrompt
|
||||
},
|
||||
settings: {
|
||||
replyPureTextCallback: undefined
|
||||
replyPureTextCallback: undefined,
|
||||
enableGroupContext: Config.enableGroupContext
|
||||
}
|
||||
}) {
|
||||
if (!conversation) {
|
||||
|
|
@ -151,7 +152,9 @@ class Core {
|
|||
messages: [],
|
||||
createdAt: Date.now()
|
||||
}
|
||||
logger.info(JSON.stringify(conversations))
|
||||
if (Config.debug) {
|
||||
logger.debug(JSON.stringify(conversations))
|
||||
}
|
||||
const previousCachedMessages = SydneyAIClient.getMessagesForConversation(conversations.messages, conversation.parentMessageId)
|
||||
.map((message) => {
|
||||
return {
|
||||
|
|
@ -160,14 +163,14 @@ class Core {
|
|||
}
|
||||
})
|
||||
let system = opt.system.bing
|
||||
if (Config.enableGroupContext && e.isGroup) {
|
||||
if (opt.settings.enableGroupContext && e.isGroup) {
|
||||
let chats = await getChatHistoryGroup(e, Config.groupContextLength)
|
||||
const namePlaceholder = '[name]'
|
||||
const defaultBotName = 'Copilot'
|
||||
const groupContextTip = Config.groupContextTip
|
||||
let botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname
|
||||
system = system.replaceAll(namePlaceholder, botName || defaultBotName) +
|
||||
((Config.enableGroupContext && e.group_id) ? groupContextTip : '')
|
||||
((opt.settings.enableGroupContext && e.group_id) ? groupContextTip : '')
|
||||
system += 'Attention, you are currently chatting in a qq group, then one who asks you now is' + `${e.sender.card || e.sender.nickname}(${e.sender.user_id}).`
|
||||
system += `the group name is ${e.group.name || e.group_name}, group id is ${e.group_id}.`
|
||||
system += `Your nickname is ${botName} in the group,`
|
||||
|
|
@ -434,7 +437,7 @@ class Core {
|
|||
option.completionParams = {}
|
||||
}
|
||||
promptAddition && (prompt += promptAddition)
|
||||
option.systemMessage = await handleSystem(e, opts.systemMessage)
|
||||
option.systemMessage = await handleSystem(e, opts.systemMessage, opt.settings)
|
||||
if (Config.enableChatSuno) {
|
||||
option.systemMessage += '如果我要求你生成音乐或写歌,你需要回复适合Suno生成音乐的信息。请使用Verse、Chorus、Bridge、Outro和End等关键字对歌词进行分段,如[Verse 1]。音乐信息需要使用markdown包裹的JSON格式回复给我,结构为```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```。'
|
||||
}
|
||||
|
|
@ -580,14 +583,14 @@ class Core {
|
|||
client.addTools(tools)
|
||||
}
|
||||
let system = opt.system.gemini
|
||||
if (Config.enableGroupContext && e.isGroup) {
|
||||
if (opt.settings.enableGroupContext && e.isGroup) {
|
||||
let chats = await getChatHistoryGroup(e, Config.groupContextLength)
|
||||
const namePlaceholder = '[name]'
|
||||
const defaultBotName = 'GeminiPro'
|
||||
const groupContextTip = Config.groupContextTip
|
||||
let botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname
|
||||
system = system.replaceAll(namePlaceholder, botName || defaultBotName) +
|
||||
((Config.enableGroupContext && e.group_id) ? groupContextTip : '')
|
||||
((opt.settings.enableGroupContext && e.group_id) ? groupContextTip : '')
|
||||
system += 'Attention, you are currently chatting in a qq group, then one who asks you now is' + `${e.sender.card || e.sender.nickname}(${e.sender.user_id}).`
|
||||
system += `the group name is ${e.group.name || e.group_name}, group id is ${e.group_id}.`
|
||||
system += `Your nickname is ${botName} in the group,`
|
||||
|
|
@ -631,7 +634,7 @@ class Core {
|
|||
Current date: ${currentDate}`
|
||||
let maxModelTokens = getMaxModelTokens(completionParams.model)
|
||||
// let system = promptPrefix
|
||||
let system = await handleSystem(e, promptPrefix, maxModelTokens)
|
||||
let system = await handleSystem(e, promptPrefix, opt.settings)
|
||||
if (Config.enableChatSuno) {
|
||||
system += 'If I ask you to generate music or write songs, you need to reply with information suitable for Suno to generate music. Please use keywords such as Verse, Chorus, Bridge, Outro, and End to segment the lyrics, such as [Verse 1], The returned song information needs to be wrapped in JSON format and sent to me in Markdown format. The message structure is ` ` JSON {"option": "Suno", "tags": "style", "title": "title of The Song", "lyrics": "lyrics"} `.'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
* @param msg
|
||||
*/
|
||||
export function filterResponseChunk (msg) {
|
||||
if (!msg || typeof msg !== 'string') {
|
||||
if (!msg) {
|
||||
return false
|
||||
}
|
||||
if (typeof msg !== 'string') {
|
||||
return msg
|
||||
}
|
||||
if (!msg.trim()) {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue