2023-05-12 18:04:58 +08:00
|
|
|
import axios from "./axios";
|
2023-05-12 15:53:39 +08:00
|
|
|
import {AI_AVATAR} from "./env";
|
|
|
|
|
|
|
|
|
|
class BaseModel {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
for (const k in props) {
|
|
|
|
|
this[k] = props[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ChatGPT extends BaseModel {
|
2023-05-12 18:12:21 +08:00
|
|
|
static base = "https://chatwithai.pages.dev"
|
|
|
|
|
|
2023-05-12 15:53:39 +08:00
|
|
|
constructor() {
|
|
|
|
|
super({
|
|
|
|
|
avatar: AI_AVATAR,
|
|
|
|
|
name: 'ChatGPT',
|
|
|
|
|
id: "gpt-3.5-turbo",
|
|
|
|
|
desc: "ChatGPT-3.5所基于的模型"
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-05-12 17:32:54 +08:00
|
|
|
|
2023-05-12 18:04:58 +08:00
|
|
|
async chat(history, callback) {
|
2023-05-12 18:12:21 +08:00
|
|
|
return await axios.post(ChatGPT.base + "/v1/chat/completions")
|
2023-05-12 17:32:54 +08:00
|
|
|
}
|
2023-05-12 15:53:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ChatGLM extends BaseModel {
|
2023-05-12 18:12:21 +08:00
|
|
|
static base = "https://chatglm.cn/chatglm/backend-api"
|
|
|
|
|
|
2023-05-12 15:53:39 +08:00
|
|
|
constructor() {
|
|
|
|
|
super({
|
|
|
|
|
avatar: AI_AVATAR,
|
|
|
|
|
name: 'ChatGLM',
|
|
|
|
|
id: "chatglm-6b",
|
|
|
|
|
desc: "ChatGLM-6B所基于的模型"
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-05-12 18:12:21 +08:00
|
|
|
|
|
|
|
|
async chat(history, callback) {
|
|
|
|
|
const context = await axios.post(ChatGPT.base + "/v1/stream_context").then(res => res.json());
|
|
|
|
|
return await axios.get(ChatGPT.base + "/v1/stream", {params: context.result})
|
|
|
|
|
}
|
2023-05-12 15:53:39 +08:00
|
|
|
}
|