先立个TODO等着准备集成new Bing

This commit is contained in:
2023-06-02 22:42:44 +08:00
parent 32592f3d6d
commit e4c9d2a294
2 changed files with 30 additions and 10 deletions

View File

@@ -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所基于的互联网模型"
}