Chore: Optimize some code logic and add support for chat context in '锅巴面板' and 'chatgpt帮助' (#310)

* Optimized code logic and added support for chat context in '锅巴面板' and 'chatgpt帮助'

In this commit, I have optimized certain code logic to improve the performance of the application. Additionally, I have added support for chat context in croutons and help, which will enhance the user experience and make the chatbot more user-friendly. This feature will allow users to maintain a better understanding of the conversation flow and context, and will ultimately lead to more successful interactions with the chatbot.

* Update chat.js

---------

Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
Sean Murphy 2023-04-03 11:11:18 +08:00 committed by GitHub
parent 84eabee14d
commit 68bb1f221e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 47 deletions

View file

@ -798,27 +798,9 @@ export class chatgpt extends plugin {
})
}
if (useTTS) {
if (Config.ttsSpace && response.length <= Config.ttsAutoFallbackThreshold) {
let audioErr = false
try {
let wav = await generateAudio(response, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
await e.reply(segment.record(wav))
} catch (err) {
await this.reply('合成语音发生错误,我用文本回复你吧')
audioErr = true
}
if (Config.alsoSendText || audioErr) {
await this.reply(await convertFaces(response, Config.enableRobotAt, e), e.isGroup)
if (quotemessage.length > 0) {
this.reply(await makeForwardMsg(this.e, quotemessage))
}
if (Config.enableSuggestedResponses && chatMessage.suggestedResponses) {
this.reply(`建议的回复:\n${chatMessage.suggestedResponses}`)
}
}
} else {
await this.reply('你没有配置转语音API或者文字太长了哦我用文本回复你吧')
await this.reply(`${response}`, e.isGroup)
// 先把文字回复发出去,避免过久等待合成语音
if (Config.alsoSendText) {
await this.reply(await convertFaces(response, Config.enableRobotAt, e), e.isGroup)
if (quotemessage.length > 0) {
this.reply(await makeForwardMsg(this.e, quotemessage))
}
@ -826,6 +808,18 @@ export class chatgpt extends plugin {
this.reply(`建议的回复:\n${chatMessage.suggestedResponses}`)
}
}
// 过滤‘括号’的内容不读,减少违和感
let ttsResponse = response.replace(/[(\[{<【《「『【〖【【【“‘'"@][^()\]}>】》」』】〗】】”’'@]*[)\]}>】》」』】〗】】”’'@]/g, '')
if (Config.ttsSpace && ttsResponse.length <= Config.ttsAutoFallbackThreshold) {
try {
let wav = await generateAudio(ttsResponse, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
await e.reply(segment.record(wav))
} catch (err) {
await this.reply('合成语音发生错误~')
}
} else {
await this.reply('你没有配置转语音API或者文字太长了哦')
}
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
// todo use next api of chatgpt to complete incomplete respoonse
try {