mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
添加获取必应Token及必应Token轻校验 (#157)
* feat: api3 WIP * feat: add support for proxy of openai * fix: if no proxy * fix: optimize help message * 增加必应token轻校验 经测试必应token固定长度215,但内容不确定 * feat: 绑定bing token后测试一下 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
fffa8191d5
commit
6f60cd0ebc
1 changed files with 25 additions and 1 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import plugin from '../../../lib/plugins/plugin.js'
|
import plugin from '../../../lib/plugins/plugin.js'
|
||||||
|
import {Config} from "../config/index.js";
|
||||||
|
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
|
||||||
|
|
||||||
export class ChatgptManagement extends plugin {
|
export class ChatgptManagement extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
|
|
@ -92,7 +94,29 @@ export class ChatgptManagement extends plugin {
|
||||||
async saveBingToken () {
|
async saveBingToken () {
|
||||||
if (!this.e.msg) return
|
if (!this.e.msg) return
|
||||||
let token = this.e.msg
|
let token = this.e.msg
|
||||||
// todo 未知bing token是什么样的,有号的可以加个校验在这
|
if (token.length < 215) {
|
||||||
|
await this.reply('Bing Token格式错误,请确定获取了有效的_U Cookie或完整的Cookie', true)
|
||||||
|
this.finish('saveToken')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let cookie = undefined
|
||||||
|
if (token?.indexOf('=') > -1) {
|
||||||
|
cookie = token
|
||||||
|
}
|
||||||
|
const bingAIClient = new BingAIClient({
|
||||||
|
userToken: token, // "_U" cookie from bing.com
|
||||||
|
cookie,
|
||||||
|
debug: Config.debug
|
||||||
|
})
|
||||||
|
// 异步就好了,不卡着这个context了
|
||||||
|
bingAIClient.createNewConversation().then(async res => {
|
||||||
|
if (res.clientId) {
|
||||||
|
logger.info("bing token 有效")
|
||||||
|
} else {
|
||||||
|
logger.error('bing token 无效', res)
|
||||||
|
await this.reply(`经检测,Bing Token无效。来自Bing的错误提示:${res.result?.message}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
await redis.set('CHATGPT:BING_TOKEN', token)
|
await redis.set('CHATGPT:BING_TOKEN', token)
|
||||||
await this.reply('Bing Token设置成功', true)
|
await this.reply('Bing Token设置成功', true)
|
||||||
this.finish('saveBingToken')
|
this.finish('saveBingToken')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue