改造请求headers,并优化初始请求
This commit is contained in:
@@ -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无效或网络波动,请重新尝试");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user