diff --git a/src/components/settings.vue b/src/components/settings.vue index 5cf85b8..a454898 100644 --- a/src/components/settings.vue +++ b/src/components/settings.vue @@ -4,7 +4,7 @@ + @click="settings.model=new m()"/> @@ -50,7 +50,7 @@ export default { } }, computed: { - models: () => Object.values(models).map((model => new model())), + models: () => Object.values(models), account: v => v.settings.account || {usage: 0, total: 0} }, methods: { diff --git a/src/utils/models.js b/src/utils/models.js index 7c7d2c9..5a07abf 100644 --- a/src/utils/models.js +++ b/src/utils/models.js @@ -7,25 +7,28 @@ class BaseModel { for (const k in props) { this[k] = props[k]; } + this.headers = { + "Content-Type": "application/json", + Accept: "application/json", + } } setApiKey(key) { this.apiKey = key - this.headers = { - "Content-Type": "application/json", - Accept: "application/json", - Authorization: `Bearer ${key}` - } + this.headers.Authorization = `Bearer ${key}` } } export class ChatGPT extends BaseModel { static base = "https://chatwithai.pages.dev" + static avatar = AI_AVATAR + static name = "ChatGPT" + static id = "gpt-3.5-turbo" + static desc = "ChatGPT-3.5所基于的模型" - constructor() { - super({ - avatar: AI_AVATAR, name: 'ChatGPT', id: "gpt-3.5-turbo", desc: "ChatGPT-3.5所基于的模型", - }); + constructor(params) { + const {avatar, name, desc, id} = ChatGPT + super({avatar, name, desc, id, ...params}) this.setApiKey(OPEN_AI_KEY) } @@ -73,18 +76,20 @@ export class ChatGPT extends BaseModel { */ export class ChatGLM extends BaseModel { static base = "https://maas.aminer.cn/api/paas" + static avatar = "https://cdn.cunwuyun.cn/chat/chatglm.svg" + static name = "ChatGLM" + static id = "chatglm-130b" + static desc = "ChatGLM-130B所基于的模型" - constructor() { - super({ - avatar: "https://cdn.cunwuyun.cn/chat/chatglm.svg", - name: 'ChatGLM', id: "chatglm-130b", desc: "ChatGLM-130B所基于的模型" - }); + constructor(params) { + const {avatar, name, desc, id} = ChatGLM + super({avatar, name, desc, id, ...params}) this.getToken().then(e => this.setApiKey(e)) } getToken() { const encrypted = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMZXxmDh2Rs1lh3Ymud1eVBjds/9SfjczHJFpNe9+0FsUffILVMTBcTqmdPZxjC6M1Ad2EHaHMWXZuc0fIc4Lh8CAwEAAQ==" - return axios.post(ChatGLM.base + "/passApiToken/createApiToken", {apiKey: "4e3ceff669c143dfa09e763663aa72cd", encrypted}, { + return axios.post(ChatGLM.base + "/passApiToken/createApiToken", JSON.stringify({apiKey: "4e3ceff669c143dfa09e763663aa72cd", encrypted}), { headers: this.headers, }).then(res => res.json()).then(data => data?.token || "key无效或网络波动,请重新尝试"); }