fix: 收拾一下

This commit is contained in:
ikechan8370 2023-06-25 00:52:13 +08:00
parent a70b25987e
commit 9c3caec780
5 changed files with 155 additions and 102 deletions

View file

@ -1931,6 +1931,7 @@ export class chatgpt extends plugin {
if (conversation) {
option = Object.assign(option, conversation)
}
if (Config.smartMode) {
let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner'
let sender = e.sender.user_id
let serpTool
@ -1954,7 +1955,6 @@ export class chatgpt extends plugin {
}
let tools = [
// new SendAvatarTool(),
// new SendDiceTool(),
new EditCardTool(),
@ -2021,6 +2021,8 @@ export class chatgpt extends plugin {
logger.mark(`function ${name} execution result: ${functionResult}`)
option.parentMessageId = msg.id
option.name = name
// 不然普通用户可能会被openai限速
await delay(300)
msg = await this.chatGPTApi.sendMessage(functionResult, option, 'function')
logger.info(msg)
}
@ -2037,6 +2039,24 @@ export class chatgpt extends plugin {
}
}
return msg
} else {
let msg
try {
msg = await this.chatGPTApi.sendMessage(prompt, option)
} catch (err) {
if (err.message?.indexOf('context_length_exceeded') > 0) {
logger.warn(err)
await redis.del(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
await redis.del(`CHATGPT:WRONG_EMOTION:${e.sender.user_id}`)
await e.reply('字数超限啦,将为您自动结束本次对话。')
return null
} else {
logger.error(err)
throw new Error(err)
}
}
return msg
}
}
}
}

View file

@ -210,6 +210,11 @@ let helpData = [
icon: 'token',
title: '#chatgpt设置后台刷新token',
desc: '用于查看API余额。注意和配置的key保持同一账号。'
},
{
icon: 'token',
title: '#chatgpt(开启|关闭)智能模式',
desc: 'API模式下打开或关闭智能模式。'
}
]
},

View file

@ -1,8 +1,6 @@
import plugin from '../../../lib/plugins/plugin.js'
import { Config } from '../utils/config.js'
import { exec } from 'child_process'
import {
checkPnpm,
formatDuration,
getAzureRoleList,
getPublicIP,
@ -260,6 +258,11 @@ export class ChatgptManagement extends plugin {
reg: '^#chatgpt导入配置',
fnc: 'importConfig',
permission: 'master'
},
{
reg: '^#chatgpt(开启|关闭)智能模式$',
fnc: 'switchSmartMode',
permission: 'master'
}
]
})
@ -1006,6 +1009,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
return true
}
async versionChatGPTPlugin (e) {
await renderUrl(e, `http://127.0.0.1:${Config.serverPort || 3321}/version`, { Viewport: { width: 800, height: 600 } })
}
@ -1391,7 +1395,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
})
console.log(configJson)
const buf = Buffer.from(configJson)
e.friend.sendFile(buf, `ChatGPT-Plugin Config ${new Date}.json`)
e.friend.sendFile(buf, `ChatGPT-Plugin Config ${new Date()}.json`)
return true
}
@ -1461,11 +1465,28 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
}
} else {
await this.reply(`未找到配置文件`, false)
await this.reply('未找到配置文件', false)
return false
}
this.finish('doImportConfig')
}
async switchSmartMode (e) {
if (e.msg.includes('开启')) {
if (Config.smartMode) {
await e.reply('已经开启了')
return
}
Config.smartMode = true
await e.reply('好的已经打开智能模式注意API额度哦')
} else {
if (!Config.smartMode) {
await e.reply('已经是关闭得了')
return
}
Config.smartMode = false
await e.reply('好的,已经关闭智能模式')
}
}
}

View file

@ -317,9 +317,15 @@ export function supportGuoba () {
{
field: 'model',
label: 'OpenAI 模型',
bottomHelpMessage: 'gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301。默认为gpt-3.5-turbogpt-4需账户支持',
bottomHelpMessage: 'gpt-4, gpt-4-0613, gpt-4-32k, gpt-4-32k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k-0613。默认为gpt-3.5-turbogpt-4需账户支持',
component: 'Input'
},
{
field: 'smartMode',
label: '智能模式',
bottomHelpMessage: '仅建议gpt-4-32k和gpt-3.5-turbo-16k-0613开启gpt-4-0613也可。开启后机器人可以群管、收发图片、发视频发音乐、联网搜索等。注意较费token。',
component: 'Switch'
},
{
field: 'openAiBaseUrl',
label: 'OpenAI API服务器地址',

View file

@ -129,6 +129,7 @@ const defaultConfig = {
azSerpKey: '',
serpSource: 'ikechan8370',
extraUrl: 'https://cpe.ikechan8370.com',
smartMode: false,
version: 'v2.7.0'
}
const _path = process.cwd()