mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: bing绘图(beta)
This commit is contained in:
parent
da5adc0d10
commit
98943bee9a
2 changed files with 150 additions and 0 deletions
29
apps/draw.js
29
apps/draw.js
|
|
@ -3,6 +3,7 @@ import { createImage, editImage, imageVariation } from '../utils/dalle.js'
|
|||
import { makeForwardMsg } from '../utils/common.js'
|
||||
import _ from 'lodash'
|
||||
import { Config } from '../utils/config.js'
|
||||
import BingDrawClient from '../utils/BingDraw.js'
|
||||
|
||||
export class dalle extends plugin {
|
||||
constructor (e) {
|
||||
|
|
@ -27,6 +28,10 @@ export class dalle extends plugin {
|
|||
{
|
||||
reg: '^#(chatgpt|dalle)编辑图片',
|
||||
fnc: 'edit'
|
||||
},
|
||||
{
|
||||
reg: '^#bing(画图|绘图)',
|
||||
fnc: 'bingDraw'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -222,4 +227,28 @@ export class dalle extends plugin {
|
|||
await redis.del(`CHATGPT:EDIT:${e.sender.user_id}`)
|
||||
}
|
||||
}
|
||||
|
||||
async bingDraw (e) {
|
||||
let prompt = e.msg.replace(/^#bing(画图|绘图)/, '')
|
||||
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
||||
if (!bingToken) {
|
||||
throw new Error('未绑定Bing Cookie,请使用#chatgpt设置必应token命令绑定Bing Cookie')
|
||||
}
|
||||
const bingTokens = bingToken.split('|')
|
||||
// 负载均衡
|
||||
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
|
||||
// sydney下不需要保证同一token
|
||||
const select = Math.floor(Math.random() * bingTokens.length)
|
||||
bingToken = bingTokens[select]
|
||||
}
|
||||
let client = new BingDrawClient({
|
||||
baseUrl: 'https://bing.ikechan8370.com',
|
||||
userToken: bingToken
|
||||
})
|
||||
try {
|
||||
await client.getImages(prompt, e)
|
||||
} catch (e) {
|
||||
await e.reply('绘图失败:' + e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue