mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
Merge branch 'v2' of https://github.com/ikechan8370/chatgpt-plugin into v2
This commit is contained in:
commit
2c9008ea56
3 changed files with 119 additions and 14 deletions
|
|
@ -134,6 +134,7 @@ const newFetch = (url, options = {}) => {
|
||||||
export class chatgpt extends plugin {
|
export class chatgpt extends plugin {
|
||||||
constructor () {
|
constructor () {
|
||||||
let toggleMode = Config.toggleMode
|
let toggleMode = Config.toggleMode
|
||||||
|
let apiStream = Config.apiStream
|
||||||
super({
|
super({
|
||||||
/** 功能名称 */
|
/** 功能名称 */
|
||||||
name: 'ChatGpt 对话',
|
name: 'ChatGpt 对话',
|
||||||
|
|
@ -291,6 +292,7 @@ export class chatgpt extends plugin {
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
this.toggleMode = toggleMode
|
this.toggleMode = toggleMode
|
||||||
|
this.apiStream = apiStream
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2272,7 +2274,7 @@ export class chatgpt extends plugin {
|
||||||
let option = {
|
let option = {
|
||||||
timeoutMs: 600000,
|
timeoutMs: 600000,
|
||||||
completionParams,
|
completionParams,
|
||||||
stream: true,
|
stream: this.apiStream,
|
||||||
onProgress: (data) => {
|
onProgress: (data) => {
|
||||||
if (Config.debug) {
|
if (Config.debug) {
|
||||||
logger.info(data?.text || data.functionCall || data)
|
logger.info(data?.text || data.functionCall || data)
|
||||||
|
|
|
||||||
59
apps/draw.js
59
apps/draw.js
|
|
@ -4,6 +4,7 @@ import { makeForwardMsg } from '../utils/common.js'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { Config } from '../utils/config.js'
|
import { Config } from '../utils/config.js'
|
||||||
import BingDrawClient from '../utils/BingDraw.js'
|
import BingDrawClient from '../utils/BingDraw.js'
|
||||||
|
import fetch from 'node-fetch'
|
||||||
|
|
||||||
export class dalle extends plugin {
|
export class dalle extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
|
|
@ -32,11 +33,67 @@ export class dalle extends plugin {
|
||||||
{
|
{
|
||||||
reg: '^#bing(画图|绘图)',
|
reg: '^#bing(画图|绘图)',
|
||||||
fnc: 'bingDraw'
|
fnc: 'bingDraw'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
reg: '^#dalle3(画图|绘图)',
|
||||||
|
fnc: 'dalle3'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dalle3
|
||||||
|
async dalle3 (e) {
|
||||||
|
if (!Config.enableDraw) {
|
||||||
|
this.reply('画图功能未开启')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let ttl = await redis.ttl(`CHATGPT:DALLE3:${e.sender.user_id}`)
|
||||||
|
if (ttl > 0 && !e.isMaster) {
|
||||||
|
this.reply(`冷却中,请${ttl}秒后再试`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let prompt = e.msg.replace(/^#?dalle3(画图|绘图)/, '').trim()
|
||||||
|
console.log('draw方法被调用,消息内容:', prompt)
|
||||||
|
await redis.set(`CHATGPT:DALLE3:${e.sender.user_id}`, 'c', { EX: 30 })
|
||||||
|
await this.reply('正在为您绘制大小为1024x1024的1张图片,预计消耗0.24美元余额,请稍候……')
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${Config.openAiBaseUrl}/images/generations`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${Config.apiKey}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: 'dall-e-3',
|
||||||
|
prompt,
|
||||||
|
n: 1,
|
||||||
|
size: '1024x1024',
|
||||||
|
response_format: 'b64_json'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// 如果需要,可以解析响应体
|
||||||
|
const dataJson = await response.json()
|
||||||
|
console.log(dataJson)
|
||||||
|
if (dataJson.error) {
|
||||||
|
e.reply(`画图失败:${dataJson.error?.code}:${dataJson.error?.message}`)
|
||||||
|
await redis.del(`CHATGPT:DALLE3:${e.sender.user_id}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (dataJson.data[0].b64_json) {
|
||||||
|
e.reply(`描述:${dataJson.data[0].revised_prompt}`)
|
||||||
|
e.reply(segment.image(`base64://${dataJson.data[0].b64_json}`))
|
||||||
|
} else if (dataJson.data[0].url) {
|
||||||
|
e.reply(`哈哈哈,图来了~\n防止图💥,附上链接:\n${dataJson.data[0].url}`)
|
||||||
|
e.reply(segment.image(dataJson.data[0].url))
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err)
|
||||||
|
this.reply(`画图失败: ${err}`, true)
|
||||||
|
await redis.del(`CHATGPT:DALLE3:${e.sender.user_id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async draw (e) {
|
async draw (e) {
|
||||||
if (!Config.enableDraw) {
|
if (!Config.enableDraw) {
|
||||||
this.reply('画图功能未开启')
|
this.reply('画图功能未开启')
|
||||||
|
|
@ -215,7 +272,7 @@ export class dalle extends plugin {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let images = (await editImage(imgUrl, position.split(',').map(p => parseInt(p, 10)), prompt, num, size))
|
let images = (await editImage(imgUrl, position.split(',').map(p => parseInt(p, 10)), prompt, num, size))
|
||||||
.map(image => segment.image(`base64://${image}`))
|
.map(image => segment.image(`base64://${image}`))
|
||||||
if (images.length > 1) {
|
if (images.length > 1) {
|
||||||
this.reply(await makeForwardMsg(e, images, prompt))
|
this.reply(await makeForwardMsg(e, images, prompt))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -335,6 +335,16 @@ export class ChatgptManagement extends plugin {
|
||||||
reg: '^#chatgpt必应(禁用|禁止|关闭|启用|开启)搜索$',
|
reg: '^#chatgpt必应(禁用|禁止|关闭|启用|开启)搜索$',
|
||||||
fnc: 'switchBingSearch',
|
fnc: 'switchBingSearch',
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
reg: '^#chatgpt查看当前配置$',
|
||||||
|
fnc: 'queryConfig',
|
||||||
|
permission: 'master'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
reg: '^#chatgpt(开启|关闭)(api|API)流$',
|
||||||
|
fnc: 'switchStream',
|
||||||
|
permission: 'master'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
@ -1682,26 +1692,20 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
||||||
|
|
||||||
async setXinghuoModel (e) {
|
async setXinghuoModel (e) {
|
||||||
this.setContext('saveXinghuoModel')
|
this.setContext('saveXinghuoModel')
|
||||||
await this.reply('1:星火V1.5\n2:星火V2\n3:星火V3\n4:星火助手')
|
await this.reply('1:星火V1.5\n2:星火V2\n3:星火V3\n4:星火V3.5\n5:星火助手')
|
||||||
await this.reply('请发送序号', true)
|
await this.reply('请发送序号', true)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async switchBingSearch (e) {
|
|
||||||
if (e.msg.includes('启用') || e.msg.includes('开启')) {
|
|
||||||
Config.sydneyEnableSearch = true
|
|
||||||
await e.reply('已开启必应搜索')
|
|
||||||
} else {
|
|
||||||
Config.sydneyEnableSearch = false
|
|
||||||
await e.reply('已禁用必应搜索')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async saveXinghuoModel (e) {
|
async saveXinghuoModel (e) {
|
||||||
if (!this.e.msg) return
|
if (!this.e.msg) return
|
||||||
let token = this.e.msg
|
let token = this.e.msg
|
||||||
let ver
|
let ver
|
||||||
switch (token) {
|
switch (token) {
|
||||||
|
case '4':
|
||||||
|
ver = 'V3.5'
|
||||||
|
Config.xhmode = 'apiv3.5'
|
||||||
|
break
|
||||||
case '3':
|
case '3':
|
||||||
ver = 'V3'
|
ver = 'V3'
|
||||||
Config.xhmode = 'apiv3'
|
Config.xhmode = 'apiv3'
|
||||||
|
|
@ -1714,7 +1718,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
||||||
ver = 'V1.5'
|
ver = 'V1.5'
|
||||||
Config.xhmode = 'api'
|
Config.xhmode = 'api'
|
||||||
break
|
break
|
||||||
case '4':
|
case '5':
|
||||||
ver = '助手'
|
ver = '助手'
|
||||||
Config.xhmode = 'assistants'
|
Config.xhmode = 'assistants'
|
||||||
break
|
break
|
||||||
|
|
@ -1724,4 +1728,46 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
||||||
await this.reply(`已成功切换到星火${ver}`, true)
|
await this.reply(`已成功切换到星火${ver}`, true)
|
||||||
this.finish('saveXinghuoModel')
|
this.finish('saveXinghuoModel')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async switchBingSearch (e) {
|
||||||
|
if (e.msg.includes('启用') || e.msg.includes('开启')) {
|
||||||
|
Config.sydneyEnableSearch = true
|
||||||
|
await e.reply('已开启必应搜索')
|
||||||
|
} else {
|
||||||
|
Config.sydneyEnableSearch = false
|
||||||
|
await e.reply('已禁用必应搜索')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async queryConfig (e) {
|
||||||
|
let use = await redis.get('CHATGPT:USE')
|
||||||
|
let config = []
|
||||||
|
config.push(`当前模式:${use}`)
|
||||||
|
config.push(`\n当前API模型:${Config.model}`)
|
||||||
|
if (e.isPrivate) {
|
||||||
|
config.push(`\n当前APIKey:${Config.apiKey}`)
|
||||||
|
config.push(`\n当前API反代:${Config.openAiBaseUrl}`)
|
||||||
|
config.push(`\n当前必应反代:${Config.sydneyReverseProxy}`)
|
||||||
|
}
|
||||||
|
config.push(`\n当前星火模型:${Config.xhmode}`)
|
||||||
|
e.reply(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
async switchStream (e) {
|
||||||
|
if (e.msg.includes('开启')) {
|
||||||
|
if (Config.apiStream) {
|
||||||
|
await e.reply('已经开启了')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Config.apiStream = true
|
||||||
|
await e.reply('好的,已经打开API流式输出')
|
||||||
|
} else {
|
||||||
|
if (!Config.apiStream) {
|
||||||
|
await e.reply('已经是关闭得了')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Config.apiStream = false
|
||||||
|
await e.reply('好的,已经关闭API流式输出')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue