chatgpt-plugin/apps/history.js
Sean Murphy b687d45897
为azure语音模式添加说话风格配置,支持vits语音模式中文回答转日语语音输出,添加翻译功能,支持指令切换语音模式,支持查看当前语音模式下的支持角色列表 (#404)
* feat: add support for ‘greeting’ and ‘global reply mode’ commands, improve variable naming and remove unnecessary backend output.

* feat: Add support for black and white lists, global reply mode and voice role settings, private chat switch, and active greeting configuration. Refactor some variable names and comment out redundant code for better readability and reduced backend output.

* feat: 为新功能完善了帮助面板

* docs: 完善了‘打招呼’的帮助说明

* Commit Type: feat, bugfix

Add functionality to view plugin command table, fix bug in blacklist/whitelist, and fix bug where chat mode can still be used in private messaging when disabled.

* Commit Type: feat, bugfix

Add functionality to view plugin command table, fix bug in blacklist/whitelist, and fix bug where chat mode can still be used in private messaging when disabled.

* refactor: Remove redundant log output.

* Refactor: optimize code logic

* Fix: 修复绘图指令表被抢指令的bug。

* Refactor:1. Add support for automatically translating replies to Japanese and generating voice messages in VITS voice mode (please monitor remaining quota after enabling). 2. Add translation function. 3. Add emotion configuration for Azure voice mode, allowing the robot to select appropriate emotional styles for replies.

* Refactor:Handle the issue of exceeding character setting limit caused by adding emotion configuration.

* Fix: fix bugs

* Refactor: Added error feedback to translation service

* Refactor: Added support for viewing the list of supported roles for each language mode, and fixed some bugs in the emotion switching feature of the auzre mode.

* Refactor: Optimized some command feedback and added owner restriction to chat record export function.

* Refactor: Optimized feedback when viewing role list to avoid excessive messages.

* Refactor: Optimized feedback when configuring multi-emotion mode.

* Feature: Added help instructions for translation feature.

* chore: Adjust help instructions for mood settings

* Fix: Fixed issue where only first line of multi-line replies were being read and Azure voice was pronouncing punctuation marks.

* Fix: Fixed bug where switching to Azure voice mode prompted for missing key and restricted ability to view voice role list to only when in voice mode.

---------

Co-authored-by: Sean <1519059137@qq.com>
Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
2023-05-04 22:55:49 +08:00

123 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import plugin from '../../../lib/plugins/plugin.js'
import { render } from '../utils/common.js'
import { Config } from '../utils/config.js'
import { KeyvFile } from 'keyv-file'
async function getKeyv () {
let Keyv
try {
Keyv = (await import('keyv')).default
} catch (error) {
throw new Error('keyv依赖未安装请使用pnpm install keyv安装')
}
return Keyv
}
export class history extends plugin {
constructor (e) {
super({
name: 'ChatGPT-Plugin 聊天记录',
dsc: '让你的聊天更加便捷!本插件支持以图片的形式导出本次对话的聊天记录,方便随时分享精彩瞬间!',
event: 'message',
priority: 500,
rule: [
{
reg: '^#(chatgpt|ChatGPT)(导出)?聊天记录$',
fnc: 'history',
permission: 'master'
}
]
})
}
async history (e) {
let use = await redis.get('CHATGPT:USE') || 'api'
let chat = []
let filtered = e.message.filter(m => m.type === 'at').filter(m => m.qq !== Bot.uin)
let queryUser = e.sender.user_id
let user = e.sender
if (filtered.length > 0) {
queryUser = filtered[0].qq
user = (await e.group.getMemberMap()).get(queryUser)
}
switch (use) {
case 'api': {
await e.reply('还不支持API模式呢')
return true
}
case 'api3': {
await e.reply('还不支持API3模式呢')
return true
}
case 'bing': {
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
const cacheOptions = {
namespace: Config.toneStyle,
store: new KeyvFile({ filename: 'cache.json' })
}
let Keyv = await getKeyv()
let conversationsCache = new Keyv(cacheOptions)
const conversation = (await conversationsCache.get(`SydneyUser_${queryUser}`)) || {
messages: [],
createdAt: Date.now()
}
let key = `CHATGPT:CONVERSATIONS_BING:${queryUser}`
let previousConversation = await redis.get(key) || JSON.stringify({})
previousConversation = JSON.parse(previousConversation)
let parentMessageId = previousConversation.parentMessageId
let tmp = {}
const previousCachedMessages = getMessagesForConversation(conversation.messages, parentMessageId)
.map((message) => {
return {
text: message.message,
author: message.role === 'User' ? 'user' : 'bot'
}
})
previousCachedMessages.forEach(m => {
if (m.author === 'user') {
tmp.prompt = m.text
} else {
tmp.response = m.text
chat.push(tmp)
tmp = {}
}
})
} else {
await e.reply('还不支持BING模式呢')
return true
}
break
}
}
if (chat.length === 0) {
await e.reply('无聊天记录', e.isGroup)
return true
}
await render(e, 'chatgpt-plugin', 'content/History/index', {
version: Config.version,
user: {
qq: queryUser,
name: user.card || user.nickname || user.user_id
},
bot: {
qq: Bot.uin,
name: Bot.nickname
},
chat
}, {})
}
}
function getMessagesForConversation (messages, parentMessageId) {
const orderedMessages = []
let currentMessageId = parentMessageId
while (currentMessageId) {
const message = messages.find((m) => m.id === currentMessageId)
if (!message) {
break
}
orderedMessages.unshift(message)
currentMessageId = message.parentMessageId
}
return orderedMessages
}