From a1b114e426ab70d49c74f64f14716d41cd49cf9e Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Thu, 6 Mar 2025 20:18:33 +0800 Subject: [PATCH] feat: qwen qwq model config (#4008) --- .../zh-cn/docs/development/upgrading/490.md | 1 + .../service/core/ai/config/provider/Qwen.json | 48 +++++++++++++ .../core/workflow/dispatch/chat/oneapi.ts | 2 +- .../app/src/pages/api/core/ai/model/test.ts | 4 +- .../app/src/pages/api/core/chat/chatTest.ts | 68 +++++++++---------- 5 files changed, 86 insertions(+), 37 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/490.md b/docSite/content/zh-cn/docs/development/upgrading/490.md index e6178dcbe..8302c2547 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/490.md +++ b/docSite/content/zh-cn/docs/development/upgrading/490.md @@ -173,6 +173,7 @@ curl --location --request POST 'https://{{host}}/api/admin/initv490' \ 1. PDF增强解析交互添加到页面上。同时内嵌 Doc2x 服务,可直接使用 Doc2x 服务解析 PDF 文件。 2. 图片自动标注,同时修改知识库文件上传部分数据逻辑和交互。 3. pg vector 插件升级 0.8.0 版本,引入迭代搜索,减少部分数据无法被检索的情况。 +4. 新增 qwen-qwq 系列模型配置。 ## ⚙️ 优化 diff --git a/packages/service/core/ai/config/provider/Qwen.json b/packages/service/core/ai/config/provider/Qwen.json index f9cef18e5..f0c7b54f1 100644 --- a/packages/service/core/ai/config/provider/Qwen.json +++ b/packages/service/core/ai/config/provider/Qwen.json @@ -122,6 +122,54 @@ "showTopP": true, "showStopSign": true }, + { + "model": "qwq-plus", + "name": "qwq-plus", + "maxContext": 128000, + "maxResponse": 8000, + "quoteMaxToken": 100000, + "maxTemperature": null, + "vision": false, + "toolChoice": true, + "functionCall": false, + "defaultSystemChatPrompt": "", + "datasetProcess": false, + "usedInClassify": false, + "customCQPrompt": "", + "usedInExtractFields": false, + "usedInQueryExtension": false, + "customExtractPrompt": "", + "usedInToolCall": true, + "defaultConfig": {}, + "fieldMap": {}, + "type": "llm", + "showTopP": false, + "showStopSign": false + }, + { + "model": "qwq-32b", + "name": "qwq-32b", + "maxContext": 128000, + "maxResponse": 8000, + "quoteMaxToken": 100000, + "maxTemperature": null, + "vision": false, + "toolChoice": true, + "functionCall": false, + "defaultSystemChatPrompt": "", + "datasetProcess": false, + "usedInClassify": false, + "customCQPrompt": "", + "usedInExtractFields": false, + "usedInQueryExtension": false, + "customExtractPrompt": "", + "usedInToolCall": true, + "defaultConfig": {}, + "fieldMap": {}, + "type": "llm", + "showTopP": false, + "showStopSign": false + }, { "model": "qwen-coder-turbo", "name": "qwen-coder-turbo", diff --git a/packages/service/core/workflow/dispatch/chat/oneapi.ts b/packages/service/core/workflow/dispatch/chat/oneapi.ts index 07035a826..d5bcd4939 100644 --- a/packages/service/core/workflow/dispatch/chat/oneapi.ts +++ b/packages/service/core/workflow/dispatch/chat/oneapi.ts @@ -264,7 +264,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise { }); const responseText = response.choices?.[0]?.message?.content; + // @ts-ignore + const reasoning_content = response.choices?.[0]?.message?.reasoning_content; - if (!responseText) { + if (!responseText && !reasoning_content) { return Promise.reject('Model response empty'); } diff --git a/projects/app/src/pages/api/core/chat/chatTest.ts b/projects/app/src/pages/api/core/chat/chatTest.ts index d7276191b..dbbe6faad 100644 --- a/projects/app/src/pages/api/core/chat/chatTest.ts +++ b/projects/app/src/pages/api/core/chat/chatTest.ts @@ -204,44 +204,42 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { }); // save chat - if (!res.closed) { - const isInteractiveRequest = !!getLastInteractiveValue(histories); - const { text: userInteractiveVal } = chatValue2RuntimePrompt(userQuestion.value); + const isInteractiveRequest = !!getLastInteractiveValue(histories); + const { text: userInteractiveVal } = chatValue2RuntimePrompt(userQuestion.value); - const newTitle = isPlugin - ? variables.cTime ?? getSystemTime(timezone) - : getChatTitleFromChatMessage(userQuestion); + const newTitle = isPlugin + ? variables.cTime ?? getSystemTime(timezone) + : getChatTitleFromChatMessage(userQuestion); - const aiResponse: AIChatItemType & { dataId?: string } = { - dataId: responseChatItemId, - obj: ChatRoleEnum.AI, - value: assistantResponses, - [DispatchNodeResponseKeyEnum.nodeResponse]: flowResponses - }; + const aiResponse: AIChatItemType & { dataId?: string } = { + dataId: responseChatItemId, + obj: ChatRoleEnum.AI, + value: assistantResponses, + [DispatchNodeResponseKeyEnum.nodeResponse]: flowResponses + }; - if (isInteractiveRequest) { - await updateInteractiveChat({ - chatId, - appId: app._id, - userInteractiveVal, - aiResponse, - newVariables - }); - } else { - await saveChat({ - chatId, - appId: app._id, - teamId, - tmbId: tmbId, - nodes, - appChatConfig: chatConfig, - variables: newVariables, - isUpdateUseTime: false, // owner update use time - newTitle, - source: ChatSourceEnum.test, - content: [userQuestion, aiResponse] - }); - } + if (isInteractiveRequest) { + await updateInteractiveChat({ + chatId, + appId: app._id, + userInteractiveVal, + aiResponse, + newVariables + }); + } else { + await saveChat({ + chatId, + appId: app._id, + teamId, + tmbId: tmbId, + nodes, + appChatConfig: chatConfig, + variables: newVariables, + isUpdateUseTime: false, // owner update use time + newTitle, + source: ChatSourceEnum.test, + content: [userQuestion, aiResponse] + }); } createChatUsage({