微调
This commit is contained in:
@@ -8,6 +8,15 @@ class BaseModel {
|
|||||||
this[k] = props[k];
|
this[k] = props[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setApiKey(key) {
|
||||||
|
this.apiKey = key
|
||||||
|
this.headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `Bearer ${key}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ChatGPT extends BaseModel {
|
export class ChatGPT extends BaseModel {
|
||||||
@@ -20,15 +29,6 @@ export class ChatGPT extends BaseModel {
|
|||||||
this.setApiKey(OPEN_AI_KEY)
|
this.setApiKey(OPEN_AI_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
setApiKey(key) {
|
|
||||||
this.apiKey = key
|
|
||||||
this.headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Accept: "application/json",
|
|
||||||
Authorization: `Bearer ${key}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async chat(history) {
|
async chat(history) {
|
||||||
const messages = history.map(e => ({role: e.role, content: e.msg}))
|
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}), {
|
return await axios.post(ChatGPT.base + "/v1/chat/completions", JSON.stringify({messages, model: this.id}), {
|
||||||
@@ -79,23 +79,13 @@ export class ChatGLM extends BaseModel {
|
|||||||
avatar: "https://cdn.cunwuyun.cn/chat/chatglm.svg",
|
avatar: "https://cdn.cunwuyun.cn/chat/chatglm.svg",
|
||||||
name: 'ChatGLM', id: "chatglm-130b", desc: "ChatGLM-130B所基于的模型"
|
name: 'ChatGLM', id: "chatglm-130b", desc: "ChatGLM-130B所基于的模型"
|
||||||
});
|
});
|
||||||
this.getToken().then(this.setApiKey)
|
this.getToken().then(e => this.setApiKey(e))
|
||||||
}
|
|
||||||
|
|
||||||
setApiKey(key) {
|
|
||||||
this.apiKey = key
|
|
||||||
this.headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Accept: "application/json",
|
|
||||||
Authorization: `Bearer ${key}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken() {
|
getToken() {
|
||||||
const encrypted = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMZXxmDh2Rs1lh3Ymud1eVBjds/9SfjczHJFpNe9+0FsUffILVMTBcTqmdPZxjC6M1Ad2EHaHMWXZuc0fIc4Lh8CAwEAAQ=="
|
const encrypted = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMZXxmDh2Rs1lh3Ymud1eVBjds/9SfjczHJFpNe9+0FsUffILVMTBcTqmdPZxjC6M1Ad2EHaHMWXZuc0fIc4Lh8CAwEAAQ=="
|
||||||
return axios.post(ChatGLM.base + "/passApiToken/createApiToken", null, {
|
return axios.post(ChatGLM.base + "/passApiToken/createApiToken", {apiKey: "4e3ceff669c143dfa09e763663aa72cd", encrypted}, {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
params: {apiKey:"4e3ceff669c143dfa09e763663aa72cd",encrypted}
|
|
||||||
}).then(res => res.json()).then(data => data?.token || "key无效或网络波动,请重新尝试");
|
}).then(res => res.json()).then(data => data?.token || "key无效或网络波动,请重新尝试");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user