mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
添加Sydney图片识别,适配tools接口 (#516)
* 修复后台API反代地址未能正确显示的问题 * 更新渲染页面配置 * 添加个人聊天模式配置 * 将用户数据获取改到common中 * 修复错误的渲染页面参数 * 修复bug * 添加Live2D * 修复渲染页面错误 * 修复渲染传入值 * 更新渲染 * 修复图表渲染bug * 调整live2d模型大小 * 修复live2d无法关闭问题 * 修复错误的传值 * 修复ai命名 * 更新渲染 * 添加用户独立设定 * 更新渲染配置适配个人设置 * 修复合并导致的渲染文件异常删除 * 修复用户数据缺失问题 * 修复旧版本数据缺失问题 * 修复bing参数不存在问题,兼容miao的截图 * 修复受限token重试时不被排除的问题 * 修复个人模式下结束对话的模式错误 * 更新渲染页面,将预览版转为正式版 * 修复传统渲染无法调用截图功能的问题 * 文字模式也进行一次缓存 * 更新README * Update README.md * 更新渲染 * 更新渲染页面 * 添加版本信息 * 遗漏参数 * 丢失引用 * 补充路由 * 添加云转码功能 * 判断node-silk是否正常合成 * 云转码提示 * 修复图片渲染出错 * 云转码支持发送Buffer * 添加云转码模式支持 * 更新描述 * 更新后台渲染页面 * 更新配置 * 更新渲染页面 * 添加云渲染 * 修复错误的接口调用 * 修复遗漏的数据转换 * 修复获取的图片数据异常问题 * 更新后台配置 * 更新渲染页面 * 修复云渲染访问地址错误 * 更新渲染页面 * 修复遗漏的模型文件 * 修复live2d问题 * 更新live2d以及相关配置 * 修复遗漏的数据参数 * 修复新live2d情况下云渲染错误的问题 * 适配云渲染1.1.2等待参数 * 添加云服务api检查 * 更新渲染页面 * 添加live2d加载检测 * 修复错误的属性判断 * 添加云渲染DPR * 更新sydney支持内容生成 * 修改文件模式语音转码接收模式 * 添加云转码时recordUrl检查 * 更新后台配置项 * 修复错误的文本描述 * 更新后台页面 * 添加全局对话模式设置,更新后台面板 * 添加第三方渲染服务适配 * 修复第三方服务器live2d加载导致的渲染失败问题 * 修复后台地址无法实时保存的问题 * 添加live2d模型透明度设置 * 合并更新 * 更新渲染页面 * 更新渲染页面 * 使dpr对本地渲染也生效 * 更新渲染页面 * 添加网页截图功能 * 添加后台配置项 * 添加配置导出和导入功能 * 运行通过参数传递用户token * 登录时将token作为参数返回 * 修复错误 * 添加密码修改和用户删除接口 * 修正密码比对 * 修复user错误 * 优化数据保存时的返回值 * 添加系统额外服务检查api * 添加AccessToken配置 * 修复错误的导入提示 * 添加ws连接 * 添加ws用户信息获取 * 修复错误的循环 * 修正ws参数 * 添加群消息获取权限 * 添加用户多端登录支持 * 修复错误的路径引用 * 修复错误的路径引用 * 修复错误 * 修复页面数据获取失败问题 * 修复异常的中断 * 添加配置视图 * 更新配置面板 * 添加用户版本信息 * 更新配置视图 * 修复错误的视图绑定 * 修改视图文件位置,添加mediaLink相关代码 * 修复错误的视图配置绑定 * 更新依赖,添加qq消息组件初始化信息获取 * 修复异常的群名称无法获取问题 * 修改注释 * 撤销对management的错误合并 * 添加Sydney图片识别功能 * 更新配置文件和后台页面 * 修改view配置 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
ffb0929ab9
commit
6ee0b0ead9
18 changed files with 488 additions and 365 deletions
91
apps/chat.js
91
apps/chat.js
|
|
@ -98,8 +98,8 @@ const defaultPropmtPrefix = ', a large language model trained by OpenAI. You ans
|
|||
const newFetch = (url, options = {}) => {
|
||||
const defaultOptions = Config.proxy
|
||||
? {
|
||||
agent: proxy(Config.proxy)
|
||||
}
|
||||
agent: proxy(Config.proxy)
|
||||
}
|
||||
: {}
|
||||
const mergedOptions = {
|
||||
...defaultOptions,
|
||||
|
|
@ -109,7 +109,7 @@ const newFetch = (url, options = {}) => {
|
|||
return fetch(url, mergedOptions)
|
||||
}
|
||||
export class chatgpt extends plugin {
|
||||
constructor () {
|
||||
constructor() {
|
||||
let toggleMode = Config.toggleMode
|
||||
super({
|
||||
/** 功能名称 */
|
||||
|
|
@ -243,7 +243,7 @@ export class chatgpt extends plugin {
|
|||
* @param e
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async getConversations (e) {
|
||||
async getConversations(e) {
|
||||
// todo 根据use返回不同的对话列表
|
||||
let keys = await redis.keys('CHATGPT:CONVERSATIONS:*')
|
||||
if (!keys || keys.length === 0) {
|
||||
|
|
@ -266,7 +266,7 @@ export class chatgpt extends plugin {
|
|||
* @param e
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async destroyConversations (e) {
|
||||
async destroyConversations(e) {
|
||||
const userData = await getUserData(e.user_id)
|
||||
const use = (userData.mode === 'default' ? null : userData.mode) || await redis.get('CHATGPT:USE')
|
||||
await redis.del(`CHATGPT:WRONG_EMOTION:${e.sender.user_id}`)
|
||||
|
|
@ -418,7 +418,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async endAllConversations (e) {
|
||||
async endAllConversations(e) {
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
let deleted = 0
|
||||
switch (use) {
|
||||
|
|
@ -502,7 +502,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply(`结束了${deleted}个用户的对话。`, true)
|
||||
}
|
||||
|
||||
async deleteConversation (e) {
|
||||
async deleteConversation(e) {
|
||||
let ats = e.message.filter(m => m.type === 'at')
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
if (use !== 'api3') {
|
||||
|
|
@ -560,7 +560,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async switch2Picture (e) {
|
||||
async switch2Picture(e) {
|
||||
let userReplySetting = await redis.get(`CHATGPT:USER:${e.sender.user_id}`)
|
||||
if (!userReplySetting) {
|
||||
userReplySetting = getDefaultReplySetting()
|
||||
|
|
@ -573,7 +573,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为图片模式')
|
||||
}
|
||||
|
||||
async switch2Text (e) {
|
||||
async switch2Text(e) {
|
||||
let userSetting = await getUserReplySetting(this.e)
|
||||
userSetting.usePicture = false
|
||||
userSetting.useTTS = false
|
||||
|
|
@ -581,7 +581,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为文字模式')
|
||||
}
|
||||
|
||||
async switch2Audio (e) {
|
||||
async switch2Audio(e) {
|
||||
switch (Config.ttsMode) {
|
||||
case 'vits-uma-genshin-honkai':
|
||||
if (!Config.ttsSpace) {
|
||||
|
|
@ -609,7 +609,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为语音模式')
|
||||
}
|
||||
|
||||
async switchTTSSource (e) {
|
||||
async switchTTSSource(e) {
|
||||
let target = e.msg.replace(/^#chatgpt语音换源/, '')
|
||||
switch (target.trim()) {
|
||||
case '1': {
|
||||
|
|
@ -632,7 +632,7 @@ export class chatgpt extends plugin {
|
|||
await e.reply('语音转换源已切换为' + Config.ttsMode)
|
||||
}
|
||||
|
||||
async setDefaultRole (e) {
|
||||
async setDefaultRole(e) {
|
||||
if (Config.ttsMode === 'vits-uma-genshin-honkai' && !Config.ttsSpace) {
|
||||
await this.reply('您没有配置vits-uma-genshin-honkai API,请前往后台管理或锅巴面板进行配置')
|
||||
return
|
||||
|
|
@ -716,7 +716,7 @@ export class chatgpt extends plugin {
|
|||
/**
|
||||
* #chatgpt
|
||||
*/
|
||||
async chatgpt (e) {
|
||||
async chatgpt(e) {
|
||||
let prompt
|
||||
if (this.toggleMode === 'at') {
|
||||
if (!e.raw_message || e.msg?.startsWith('#')) {
|
||||
|
|
@ -782,7 +782,7 @@ export class chatgpt extends plugin {
|
|||
await this.abstractChat(e, prompt, use)
|
||||
}
|
||||
|
||||
async abstractChat (e, prompt, use) {
|
||||
async abstractChat(e, prompt, use) {
|
||||
// 关闭私聊通道后不回复
|
||||
if (!e.isMaster && e.isPrivate && !Config.enablePrivateChat) {
|
||||
return false
|
||||
|
|
@ -1050,12 +1050,12 @@ export class chatgpt extends plugin {
|
|||
emotionMatch.index + emotionMatch[0].length - 1
|
||||
]
|
||||
const ttsArr =
|
||||
response.length / 2 < endIndex
|
||||
? [response.substring(startIndex), response.substring(0, startIndex)]
|
||||
: [
|
||||
response.substring(0, endIndex + 1),
|
||||
response.substring(endIndex + 1)
|
||||
]
|
||||
response.length / 2 < endIndex
|
||||
? [response.substring(startIndex), response.substring(0, startIndex)]
|
||||
: [
|
||||
response.substring(0, endIndex + 1),
|
||||
response.substring(endIndex + 1)
|
||||
]
|
||||
const match = ttsArr[0].match(emotionReg)
|
||||
response = ttsArr[1].replace(/\n/, '').trim()
|
||||
if (match) {
|
||||
|
|
@ -1064,7 +1064,7 @@ export class chatgpt extends plugin {
|
|||
(config) => config.code === ttsRoleAzure
|
||||
)
|
||||
const supportedEmotions =
|
||||
configuration.emotion && Object.keys(configuration.emotion)
|
||||
configuration.emotion && Object.keys(configuration.emotion)
|
||||
if (supportedEmotions && supportedEmotions.includes(emotion)) {
|
||||
logger.warn(`角色 ${ttsRoleAzure} 支持 ${emotion} 情绪.`)
|
||||
await redis.set(`CHATGPT:WRONG_EMOTION:${e.sender.user_id}`, '0')
|
||||
|
|
@ -1245,7 +1245,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async chatgpt1 (e) {
|
||||
async chatgpt1(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1264,7 +1264,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async chatgpt3 (e) {
|
||||
async chatgpt3(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1283,7 +1283,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async chatglm (e) {
|
||||
async chatglm(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1302,7 +1302,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async bing (e) {
|
||||
async bing(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1321,7 +1321,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async claude (e) {
|
||||
async claude(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1340,7 +1340,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async xh (e) {
|
||||
async xh(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1359,7 +1359,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async cacheContent (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
async cacheContent(e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
let cacheData = { file: '', cacheUrl: Config.cacheUrl, status: '' }
|
||||
cacheData.file = randomString()
|
||||
const cacheresOption = {
|
||||
|
|
@ -1399,7 +1399,7 @@ export class chatgpt extends plugin {
|
|||
return cacheData
|
||||
}
|
||||
|
||||
async renderImage (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
async renderImage(e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
let cacheData = await this.cacheContent(e, use, content, prompt, quote, mood, suggest, imgUrls)
|
||||
const template = use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index'
|
||||
if (!Config.oldview) {
|
||||
|
|
@ -1447,7 +1447,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async sendMessage (prompt, conversation = {}, use, e) {
|
||||
async sendMessage(prompt, conversation = {}, use, e) {
|
||||
if (!conversation) {
|
||||
conversation = {
|
||||
timeoutMs: Config.defaultTimeoutMs
|
||||
|
|
@ -1579,6 +1579,11 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
bingAIClient = new BingAIClient(bingOption)
|
||||
}
|
||||
// 写入图片数据
|
||||
if (Config.sydneyImageRecognition) {
|
||||
const image = await getImg(e)
|
||||
opt.imageUrl = image ? image[0] : undefined
|
||||
}
|
||||
response = await bingAIClient.sendMessage(prompt, opt, (token) => {
|
||||
reply += token
|
||||
})
|
||||
|
|
@ -1824,7 +1829,7 @@ export class chatgpt extends plugin {
|
|||
const defaultBotName = 'ChatGPT'
|
||||
const groupContextTip = Config.groupContextTip
|
||||
system = system.replaceAll(namePlaceholder, opt.botName || defaultBotName) +
|
||||
((Config.enableGroupContext && opt.groupId) ? groupContextTip : '')
|
||||
((Config.enableGroupContext && opt.groupId) ? groupContextTip : '')
|
||||
system += 'Attention, you are currently chatting in a qq group, then one who asks you now is' + `${opt.nickname}(${opt.qq})。`
|
||||
system += `the group name is ${opt.groupName}, group id is ${opt.groupId}。`
|
||||
if (opt.botName) {
|
||||
|
|
@ -2009,7 +2014,7 @@ export class chatgpt extends plugin {
|
|||
} else {
|
||||
tools.push(new SerpImageTool())
|
||||
tools.push(...[new SearchVideoTool(),
|
||||
new SendVideoTool()])
|
||||
new SendVideoTool()])
|
||||
}
|
||||
let funcMap = {}
|
||||
let fullFuncMap = {}
|
||||
|
|
@ -2092,7 +2097,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async newClaudeConversation (e) {
|
||||
async newClaudeConversation(e) {
|
||||
let presetName = e.msg.replace(/^#claude开启新对话/, '').trim()
|
||||
let client = new SlackClaudeClient({
|
||||
slackUserToken: Config.slackUserToken,
|
||||
|
|
@ -2123,19 +2128,19 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
logger.info('send preset: ' + preset.content)
|
||||
response = await client.sendMessage(preset.content, e) +
|
||||
await client.sendMessage(await AzureTTS.getEmotionPrompt(e), e)
|
||||
await client.sendMessage(await AzureTTS.getEmotionPrompt(e), e)
|
||||
await e.reply(response, true)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async emptyQueue (e) {
|
||||
async emptyQueue(e) {
|
||||
await redis.lTrim('CHATGPT:CHAT_QUEUE', 1, 0)
|
||||
await this.reply('已清空当前等待队列')
|
||||
}
|
||||
|
||||
async removeQueueFirst (e) {
|
||||
async removeQueueFirst(e) {
|
||||
let uid = await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
if (!uid) {
|
||||
await this.reply('当前等待队列为空')
|
||||
|
|
@ -2144,7 +2149,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async getAllConversations (e) {
|
||||
async getAllConversations(e) {
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
if (use === 'api3') {
|
||||
let conversations = await getConversations(e.sender.user_id, newFetch)
|
||||
|
|
@ -2165,7 +2170,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async joinConversation (e) {
|
||||
async joinConversation(e) {
|
||||
let ats = e.message.filter(m => m.type === 'at')
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
// if (use !== 'api3') {
|
||||
|
|
@ -2196,7 +2201,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async attachConversation (e) {
|
||||
async attachConversation(e) {
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
if (use !== 'api3') {
|
||||
await this.reply('该功能目前仅支持API3模式')
|
||||
|
|
@ -2213,7 +2218,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async totalAvailable (e) {
|
||||
async totalAvailable(e) {
|
||||
// 查询OpenAI API剩余试用额度
|
||||
let subscriptionRes = await newFetch(`${Config.openAiBaseUrl}/dashboard/billing/subscription`, {
|
||||
method: 'GET',
|
||||
|
|
@ -2222,7 +2227,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
})
|
||||
|
||||
function getDates () {
|
||||
function getDates() {
|
||||
const today = new Date()
|
||||
const tomorrow = new Date(today)
|
||||
tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
|
@ -2259,7 +2264,7 @@ export class chatgpt extends plugin {
|
|||
* @param prompt 问题
|
||||
* @param conversation 对话
|
||||
*/
|
||||
async chatgptBrowserBased (prompt, conversation) {
|
||||
async chatgptBrowserBased(prompt, conversation) {
|
||||
let option = { markdown: true }
|
||||
if (Config['2captchaToken']) {
|
||||
option.captchaToken = Config['2captchaToken']
|
||||
|
|
@ -2279,7 +2284,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async function getAvailableBingToken (conversation, throttled = []) {
|
||||
async function getAvailableBingToken(conversation, throttled = []) {
|
||||
let allThrottled = false
|
||||
if (!await redis.get('CHATGPT:BING_TOKENS')) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1353,4 +1353,4 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
|
|||
await e.reply('好的,已经关闭智能模式')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue