fix: 加了一系列管理功能

This commit is contained in:
ikechan8370 2023-03-14 19:16:21 +08:00
parent 8ea7ab07ec
commit 3f08cf4894
8 changed files with 97 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import { segment } from 'oicq'
import { createImage, editImage, imageVariation } from '../utils/dalle.js'
import { makeForwardMsg } from '../utils/common.js'
import _ from 'lodash'
import { Config } from '../utils/config.js'
export class dalle extends plugin {
constructor (e) {
@ -33,6 +34,10 @@ export class dalle extends plugin {
}
async draw (e) {
if (!Config.enableDraw) {
this.reply('画图功能未开启')
return false
}
let ttl = await redis.ttl(`CHATGPT:DRAW:${e.sender.user_id}`)
if (ttl > 0 && !e.isMaster) {
this.reply(`冷却中,请${ttl}秒后再试`)
@ -76,6 +81,10 @@ export class dalle extends plugin {
}
async variation (e) {
if (!Config.enableDraw) {
this.reply('画图功能未开启')
return false
}
let ttl = await redis.ttl(`CHATGPT:VARIATION:${e.sender.user_id}`)
if (ttl > 0 && !e.isMaster) {
this.reply(`冷却中,请${ttl}秒后再试`)
@ -123,6 +132,10 @@ export class dalle extends plugin {
}
async avatarVariation (e) {
if (!Config.enableDraw) {
this.reply('画图功能未开启')
return false
}
let ats = e.message.filter(m => m.type === 'at').filter(at => at.qq !== e.self_id)
if (ats.length > 0) {
for (let i = 0; i < ats.length; i++) {
@ -145,6 +158,10 @@ export class dalle extends plugin {
}
async edit (e) {
if (!Config.enableDraw) {
this.reply('画图功能未开启')
return false
}
let ttl = await redis.ttl(`CHATGPT:EDIT:${e.sender.user_id}`)
if (ttl > 0 && !e.isMaster) {
this.reply(`冷却中,请${ttl}秒后再试`)

View file

@ -61,6 +61,11 @@ let helpData = [
title: '#chatgpt改图',
desc: '调用OpenAI Dalle API进行改图需要有API key并消耗余额。可同时发送图片或回复图片'
},
{
icon: 'switch',
title: '#chatgpt开启/关闭画图',
desc: '开启或关闭画图功能'
}
]
},
{
@ -150,6 +155,11 @@ let helpData = [
icon: 'eat',
title: '#chatgpt设置(API|Sydney)设定',
desc: '设置AI的风格设定'
},
{
icon: 'eat',
title: '#chatgpt查看(API|Sydney)设定',
desc: '查看AI的风格设定文本形式返回设定太长可能发不出来'
}
]
},

View file

@ -94,6 +94,21 @@ export class ChatgptManagement extends plugin {
reg: '^#chatgpt设置(Bing|必应|Sydney|悉尼|sydney|bing)设定',
fnc: 'setBingPromptPrefix',
permission: 'master'
},
{
reg: '^#chatgpt(开启|关闭)画图$',
fnc: 'switchDraw',
permission: 'master'
},
{
reg: '^#chatgpt查看(API|api)设定$',
fnc: 'queryAPIPromptPrefix',
permission: 'master'
},
{
reg: '^#chatgpt查看(Bing|必应|Sydney|悉尼|sydney|bing)设定$',
fnc: 'queryBingPromptPrefix',
permission: 'master'
}
]
})
@ -298,7 +313,7 @@ export class ChatgptManagement extends plugin {
// eslint-disable-next-line no-irregular-whitespace
API模式会调用OpenAI官方提供的gpt-3.5-turbo API只需要提供API Key一般情况下该种方式响应速度更快不会像chatGPT官网一样总出现不可用的现象但注意gpt-3.5-turbo的API调用是收费的新用户有18美元试用金可用于支付价格为$0.0020/1K tokens.(问题和回答加起来算token)
API3模式会调用第三方提供的官网反代API他会帮你绕过CF防护需要提供ChatGPT的Token效果与官网和浏览器一致但稳定性不一定设置token和API2方法一样#chatgpt设置token
API3模式会调用官网反代API他会帮你绕过CF防护需要提供ChatGPT的Token效果与官网和浏览器一致设置token指令#chatgpt设置token
浏览器模式通过在本地启动Chrome等浏览器模拟用户访问ChatGPT网站使得获得和官方以及API2模式一模一样的回复质量同时保证安全性缺点是本方法对环境要求较高需要提供桌面环境和一个可用的代理能够访问ChatGPT的IP地址且响应速度不如API而且高峰期容易无法使用
@ -491,4 +506,30 @@ export class ChatgptManagement extends plugin {
await this.reply('Bing Sydney模式的设定设置成功', true)
this.finish('saveBingPromptPrefix')
}
async switchDraw (e) {
if (e.msg.indexOf('开启') > -1) {
if (Config.enableDraw) {
await this.reply('当前已经开启chatgpt画图功能', true)
} else {
Config.enableDraw = true
await this.reply('chatgpt画图功能开启成功', true)
}
} else {
if (!Config.enableDraw) {
await this.reply('当前未开启chatgpt画图功能', true)
} else {
Config.enableDraw = false
await this.reply('chatgpt画图功能关闭成功', true)
}
}
}
async queryAPIPromptPrefix (e) {
await this.reply(Config.promptPrefixOverride, true)
}
async queryBingPromptPrefix (e) {
await this.reply(Config.sydney, true)
}
}

View file

@ -154,6 +154,11 @@ export function supportGuoba () {
min: 0
}
},
{
field: 'enableDraw',
label: '绘图功能开关',
component: 'Switch'
},
{
field: 'proxy',
label: '代理服务器地址',
@ -190,6 +195,16 @@ export function supportGuoba () {
min: 0
}
},
{
field: 'sydneyFirstMessageTimeout',
label: 'Sydney模式接受首条信息超时时间',
helpMessage: '单位:毫秒',
bottomHelpMessage: '超过该时间阈值未收到Bing的任何消息则断开本次连接并重试最多重试3次失败后返回timeout waiting for first message。',
component: 'InputNumber',
componentProps: {
min: 15000
}
},
{
label: '以下为API方式(默认)的配置',
component: 'Divider'
@ -383,7 +398,13 @@ export function supportGuoba () {
{
field: 'initiativeChatGroups',
label: '主动发起聊天群聊的群号',
bottomHelpMessage: '在这些群聊里会不定时主动说一些随机的打招呼的话,用英文逗号隔开。',
bottomHelpMessage: '在这些群聊里会不定时主动说一些随机的打招呼的话用英文逗号隔开。必须配置了OpenAI Key',
component: 'Input'
},
{
field: 'helloPrompt',
label: '打招呼所说文字的引导文字',
bottomHelpMessage: '将会用这段文字询问ChatGPT由ChatGPT给出随机的打招呼文字。',
component: 'Input'
}
],

View file

@ -201,7 +201,7 @@ export default class SydneyAIClient {
onProgress,
abortController = new AbortController(),
timeout = Config.defaultTimeoutMs,
firstMessageTimeout = 15000
firstMessageTimeout = Config.sydneyFirstMessageTimeout
} = opts
if (typeof onProgress !== 'function') {
onProgress = () => {}

View file

@ -50,6 +50,7 @@ const defaultConfig = {
debug: true,
defaultTimeoutMs: 120000,
chromeTimeoutMS: 120000,
sydneyFirstMessageTimeout: 15000,
ttsSpace: '',
// https://114514.201666.xyz
huggingFaceReverseProxy: '',
@ -57,7 +58,9 @@ const defaultConfig = {
noiseScaleW: 0.668,
lengthScale: 1.2,
initiativeChatGroups: [],
version: 'v2.1.5'
enableDraw: true,
helloPrompt: '写一段话让大家来找我聊天。类似于“有人找我聊天吗?"这种风格轻松随意一点控制在20个字以内',
version: 'v2.1.6'
}
const _path = process.cwd()
let config = {}

View file

@ -24,7 +24,7 @@ const newFetch = (url, options = {}) => {
return fetch(url, mergedOptions)
}
const question = '写一段话让大家来找我聊天。类似于“有人找我聊天吗?"这种风格轻松随意一点控制在20个字以内'
const question = Config.helloPrompt || '写一段话让大家来找我聊天。类似于“有人找我聊天吗?"这种风格轻松随意一点控制在20个字以内'
export async function generateHello () {
let api = new ChatGPTAPI({

View file