From f77602124043b47d7a063e1a601e34da096b0190 Mon Sep 17 00:00:00 2001 From: Vinlic Date: Sun, 17 Mar 2024 16:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81model=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93ID=EF=BC=8C=E4=B8=8D=E4=BC=A0?= =?UTF-8?q?=E6=88=96=E8=80=85=E9=9D=9E24=E4=BD=8Did=E5=88=99=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=BD=BF=E7=94=A8GLM4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 17 +++-------------- src/api/routes/chat.ts | 5 +++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 4380cdf..98d93b3 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -13,8 +13,8 @@ import util from '@/lib/util.ts'; // 模型名称 const MODEL_NAME = 'glm'; -// 默认的智能体ID -const DEFAULT_ASSISTANT_ID = '65c32fa2a766a337422a6006'; +// 默认的智能体ID,GLM4 +const DEFAULT_ASSISTANT_ID = '65940acff94777010aa6b796'; // access_token有效期 const ACCESS_TOKEN_EXPIRES = 3600; // 最大重试次数 @@ -157,17 +157,6 @@ async function createCompletion(messages: any[], refreshToken: string, assistant // 请求流 const token = await acquireToken(refreshToken); - console.log({ - assistant_id: assistantId, - conversation_id: '', - messages: messagesPrepare(messages, refs), - meta_data: { - channel: '', - draft_id: '', - input_question_type: 'xxxx', - is_test: false - } - }); const result = await axios.post('https://chatglm.cn/chatglm/backend-api/assistant/stream', { assistant_id: assistantId, conversation_id: '', @@ -315,7 +304,7 @@ function extractRefFileUrls(messages: any[]) { * @param messages 参考gpt系列消息格式,多轮对话请完整提供上下文 */ function messagesPrepare(messages: any[], refs: any[]) { - const headPrompt = '设定:【重要】回答用户问题,不要输出说话者\n'; + const headPrompt = '设定:【重要】回答用户问题,禁止输出双方的名字\n'; const content = messages.reduce((content, message) => { if (_.isArray(message.content)) { return message.content.reduce((_content, v) => { diff --git a/src/api/routes/chat.ts b/src/api/routes/chat.ts index 5f2346b..37a3975 100644 --- a/src/api/routes/chat.ts +++ b/src/api/routes/chat.ts @@ -20,14 +20,15 @@ export default { // 随机挑选一个refresh_token const token = _.sample(tokens); const messages = request.body.messages; + const assistantId = /^[a-z0-9]{24,}$/.test(request.body.model) ? request.body.model : undefined if (request.body.stream) { - const stream = await chat.createCompletionStream(request.body.messages, token, request.body.use_search); + const stream = await chat.createCompletionStream(request.body.messages, token, assistantId); return new Response(stream, { type: "text/event-stream" }); } else - return await chat.createCompletion(messages, token, request.body.use_search); + return await chat.createCompletion(messages, token, assistantId); } }