先提交一手
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export const OPEN_AI_KEY = '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'
|
||||
//ai头像
|
||||
export const AI_AVATAR = "https://th.bing.com/th?id=ODL.3e2fbff4543f0d3632d34be6d02adc93&w=100&h=100&c=12&pcl=faf9f7&o=6&dpr=1.5&pid=13.1"
|
||||
export const AI_AVATAR = "https://cdn.cunwuyun.cn/chat/chatGPT.png"
|
||||
//用户头像
|
||||
export const USER_AVATAR = "https://avatars.githubusercontent.com/u/20533272?v=4"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {dayjs} from "element-plus";
|
||||
import axios from "./axios";
|
||||
import {AI_AVATAR, OPEN_AI_KEY} from "./env";
|
||||
|
||||
@@ -17,10 +18,16 @@ export class ChatGPT extends BaseModel {
|
||||
avatar: AI_AVATAR, name: 'ChatGPT', id: "gpt-3.5-turbo", desc: "ChatGPT-3.5所基于的模型",
|
||||
});
|
||||
this.apiKey = OPEN_AI_KEY
|
||||
this.headers = {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${this.apiKey}`
|
||||
}
|
||||
}
|
||||
|
||||
setApiKey(key) {
|
||||
this.apiKey = key
|
||||
this.headers["Authorization"] = `Bearer ${this.apiKey}`
|
||||
}
|
||||
|
||||
async chat(history) {
|
||||
@@ -41,6 +48,25 @@ export class ChatGPT extends BaseModel {
|
||||
}).then(res => res?.body?.getReader());
|
||||
}
|
||||
|
||||
async getAccount() {
|
||||
const {headers} = this
|
||||
const usages = await axios.get(ChatGPT.base + "/v1/dashboard/billing/subscription", {headers}).then(res => res.json());
|
||||
const endDate = usages.access_until
|
||||
if (endDate) {
|
||||
const startDate = new Date(endDate - 90 * 24 * 60 * 60);
|
||||
const formattedDate = time => dayjs(time).format("YYYY-MM-DD")
|
||||
return axios.get(`${ChatGPT.base}/v1/dashboard/billing/usage?start_date=${formattedDate(startDate * 1000)}&end_date=${formattedDate(endDate * 1000)}`,
|
||||
{headers}).then(res => res.json()).then(res => {
|
||||
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)
|
||||
}
|
||||
});
|
||||
} else return Promise.reject("没有权限或者网络异常,请重新尝试!")
|
||||
}
|
||||
}
|
||||
|
||||
export class ChatGLM extends BaseModel {
|
||||
@@ -48,7 +74,7 @@ export class ChatGLM extends BaseModel {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
avatar: AI_AVATAR, name: 'ChatGLM', id: "chatglm-6b", desc: "ChatGLM-6B所基于的模型"
|
||||
avatar: "https://cdn.cunwuyun.cn/chat/chatglm.svg", name: 'ChatGLM', id: "chatglm-6b", desc: "ChatGLM-6B所基于的模型"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,5 +21,11 @@ export function copyToClipboard(content) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 浅拷贝
|
||||
* @param any
|
||||
* @returns {any}
|
||||
*/
|
||||
export const scopy = (any = null) => JSON.parse(JSON.stringify(any))
|
||||
|
||||
Reference in New Issue
Block a user