改造请求headers,并优化初始请求
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<el-form-item label="语言模型">
|
<el-form-item label="语言模型">
|
||||||
<el-row class="flexWrap">
|
<el-row class="flexWrap">
|
||||||
<ai-model v-for="m in models" :model="m" small :class="{active:settings.model.id==m.id}"
|
<ai-model v-for="m in models" :model="m" small :class="{active:settings.model.id==m.id}"
|
||||||
@click="settings.model=m"/>
|
@click="settings.model=new m()"/>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="流式输出">
|
<el-form-item label="流式输出">
|
||||||
@@ -50,7 +50,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
models: () => Object.values(models).map((model => new model())),
|
models: () => Object.values(models),
|
||||||
account: v => v.settings.account || {usage: 0, total: 0}
|
account: v => v.settings.account || {usage: 0, total: 0}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -7,25 +7,28 @@ class BaseModel {
|
|||||||
for (const k in props) {
|
for (const k in props) {
|
||||||
this[k] = props[k];
|
this[k] = props[k];
|
||||||
}
|
}
|
||||||
|
this.headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setApiKey(key) {
|
setApiKey(key) {
|
||||||
this.apiKey = key
|
this.apiKey = key
|
||||||
this.headers = {
|
this.headers.Authorization = `Bearer ${key}`
|
||||||
"Content-Type": "application/json",
|
|
||||||
Accept: "application/json",
|
|
||||||
Authorization: `Bearer ${key}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ChatGPT extends BaseModel {
|
export class ChatGPT extends BaseModel {
|
||||||
static base = "https://chatwithai.pages.dev"
|
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() {
|
constructor(params) {
|
||||||
super({
|
const {avatar, name, desc, id} = ChatGPT
|
||||||
avatar: AI_AVATAR, name: 'ChatGPT', id: "gpt-3.5-turbo", desc: "ChatGPT-3.5所基于的模型",
|
super({avatar, name, desc, id, ...params})
|
||||||
});
|
|
||||||
this.setApiKey(OPEN_AI_KEY)
|
this.setApiKey(OPEN_AI_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,18 +76,20 @@ export class ChatGPT extends BaseModel {
|
|||||||
*/
|
*/
|
||||||
export class ChatGLM extends BaseModel {
|
export class ChatGLM extends BaseModel {
|
||||||
static base = "https://maas.aminer.cn/api/paas"
|
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() {
|
constructor(params) {
|
||||||
super({
|
const {avatar, name, desc, id} = ChatGLM
|
||||||
avatar: "https://cdn.cunwuyun.cn/chat/chatglm.svg",
|
super({avatar, name, desc, id, ...params})
|
||||||
name: 'ChatGLM', id: "chatglm-130b", desc: "ChatGLM-130B所基于的模型"
|
|
||||||
});
|
|
||||||
this.getToken().then(e => this.setApiKey(e))
|
this.getToken().then(e => this.setApiKey(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken() {
|
getToken() {
|
||||||
const encrypted = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMZXxmDh2Rs1lh3Ymud1eVBjds/9SfjczHJFpNe9+0FsUffILVMTBcTqmdPZxjC6M1Ad2EHaHMWXZuc0fIc4Lh8CAwEAAQ=="
|
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,
|
headers: this.headers,
|
||||||
}).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