From 6f60cd0ebc4056e0580d0af0d29212e6f94c80a6 Mon Sep 17 00:00:00 2001 From: Err0rCM <68117733+Err0rCM@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=BF=85?= =?UTF-8?q?=E5=BA=94Token=E5=8F=8A=E5=BF=85=E5=BA=94Token=E8=BD=BB?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=20(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- apps/management.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/management.js b/apps/management.js index 988c27a..414716d 100644 --- a/apps/management.js +++ b/apps/management.js @@ -1,4 +1,6 @@ import plugin from '../../../lib/plugins/plugin.js' +import {Config} from "../config/index.js"; +import { BingAIClient } from '@waylaidwanderer/chatgpt-api' export class ChatgptManagement extends plugin { constructor (e) { @@ -92,7 +94,29 @@ export class ChatgptManagement extends plugin { async saveBingToken () { if (!this.e.msg) return 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 this.reply('Bing Token设置成功', true) this.finish('saveBingToken')