From e4c9d2a2948c702364c0cd9144ab997ad959d1ca Mon Sep 17 00:00:00 2001 From: Kubbo <390378816@qq.com> Date: Fri, 2 Jun 2023 22:42:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E7=AB=8B=E4=B8=AATODO=E7=AD=89?= =?UTF-8?q?=E7=9D=80=E5=87=86=E5=A4=87=E9=9B=86=E6=88=90new=20Bing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/env.js | 3 --- src/utils/models.js | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/utils/env.js b/src/utils/env.js index 2a25dfc..6ed3a28 100644 --- a/src/utils/env.js +++ b/src/utils/env.js @@ -1,6 +1,3 @@ -export const OPEN_AI_KEY = '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' -//ai头像 -export const AI_AVATAR = "https://cdn.cunwuyun.cn/chat/chatGPT.png" //用户头像 export const USER_AVATAR = "https://avatars.githubusercontent.com/u/20533272?v=4" diff --git a/src/utils/models.js b/src/utils/models.js index eac8220..1a3d075 100644 --- a/src/utils/models.js +++ b/src/utils/models.js @@ -1,7 +1,6 @@ import {dayjs} from "element-plus"; import {nanoid} from "nanoid"; import axios from "./axios"; -import {AI_AVATAR, OPEN_AI_KEY} from "./env"; import {JSEncrypt} from "jsencrypt"; class BaseModel { @@ -25,7 +24,7 @@ class BaseModel { */ export class ChatGPT extends BaseModel { static base = "https://chatwithai.pages.dev" - static avatar = AI_AVATAR + static avatar = 'https://cdn.cunwuyun.cn/chat/chatGPT.png' static name = "ChatGPT" static id = "gpt-3.5-turbo" static desc = "ChatGPT-3.5所基于的模型" @@ -33,7 +32,7 @@ export class ChatGPT extends BaseModel { constructor(params) { const {avatar, name, desc, id} = ChatGPT super({avatar, name, desc, id, ...params}) - this.setApiKey(OPEN_AI_KEY) + this.setApiKey("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") } async chat(history) { @@ -47,7 +46,11 @@ export class ChatGPT extends BaseModel { async chatStream(history) { const messages = history.map(e => ({role: e.role, content: e.msg})) - return await axios.post(ChatGPT.base + "/v1/chat/completions", JSON.stringify({messages, model: this.id, stream: true}), { + return await axios.post(ChatGPT.base + "/v1/chat/completions", JSON.stringify({ + messages, + model: this.id, + stream: true + }), { headers: { Authorization: 'Bearer ' + this.apiKey, "Content-Type": "application/json", Accept: "application/json", }, @@ -65,7 +68,10 @@ export class ChatGPT extends BaseModel { usages.total_usage = res.total_usage const names = usages.account_name.split(" ") return { - ...usages, username: names.at(-1) + names[0], usage: (usages.total_usage / 100)?.toFixed(2), total: usages.hard_limit_usd?.toFixed(2) + ...usages, + username: names.at(-1) + names[0], + usage: (usages.total_usage / 100)?.toFixed(2), + total: usages.hard_limit_usd?.toFixed(2) } }); } else return Promise.reject("没有权限或者网络异常,请重新尝试!") @@ -128,7 +134,10 @@ export class ChatGLM extends BaseModel { async getToken() { if (this.apiKey) return await this.apiKey const encrypted = ChatGLM.encrypt(ChatGLM.publicKey) - return await axios.post(ChatGLM.base + "/passApiToken/createApiToken", JSON.stringify({apiKey: "4e3ceff669c143dfa09e763663aa72cd", encrypted}), { + return await axios.post(ChatGLM.base + "/passApiToken/createApiToken", JSON.stringify({ + apiKey: "4e3ceff669c143dfa09e763663aa72cd", + encrypted + }), { headers: this.headers, }).then(res => res.json()).then(data => data?.data); } @@ -182,7 +191,10 @@ export class ChatGLM extends BaseModel { if (usages.code == 200) { const {data} = usages return { - ...data, username: "Kubbo", usage: data.totalSpendAmount?.toFixed(4), total: data.rechargeAmount?.toFixed(4) + ...data, + username: "Kubbo", + usage: data.totalSpendAmount?.toFixed(4), + total: data.rechargeAmount?.toFixed(4) } } else return Promise.reject("没有权限或者网络异常,请重新尝试!") } @@ -200,3 +212,14 @@ export class ChatGLM extends BaseModel { }) } } + +/** + * 集成免费的New Bing搜索,TODO + */ +class NewBing extends BaseModel { + static base = "https://maas.aminer.cn/api/paas" + static avatar = "https://cdn.cunwuyun.cn/chat/chatglm.svg" + static name = "NewBing" + static id = "gpt-4" + static desc = "GPT-4所基于的互联网模型" +} \ No newline at end of file