import axios from "./axios"; import {AI_AVATAR} from "./env"; class BaseModel { constructor(props) { for (const k in props) { this[k] = props[k]; } } } export class ChatGPT extends BaseModel { static base = "https://chatwithai.pages.dev" constructor() { super({ avatar: AI_AVATAR, name: 'ChatGPT', id: "gpt-3.5-turbo", desc: "ChatGPT-3.5所基于的模型" }); } async chat(history, callback) { return await axios.post(ChatGPT.base + "/v1/chat/completions") } } export class ChatGLM extends BaseModel { static base = "https://chatglm.cn/chatglm/backend-api" constructor() { super({ avatar: AI_AVATAR, name: 'ChatGLM', id: "chatglm-6b", desc: "ChatGLM-6B所基于的模型" }); } 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}) } }