From 16832caaf6c9840df6d47324ee82a18f3fbdbaf5 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Tue, 11 Mar 2025 16:33:08 +0800 Subject: [PATCH] perf: think tag parse (#4102) --- docSite/content/zh-cn/docs/development/upgrading/491.md | 1 + packages/service/core/ai/utils.ts | 6 +++--- packages/service/core/workflow/dispatch/chat/oneapi.ts | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/491.md b/docSite/content/zh-cn/docs/development/upgrading/491.md index 1093ccafe..0e0d49403 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/491.md +++ b/docSite/content/zh-cn/docs/development/upgrading/491.md @@ -17,6 +17,7 @@ weight: 799 2. 应用拉取绑定知识库数据交由后端处理。 3. 增加依赖包安全版本检测,并升级部分依赖包。 4. 模型测试代码。 +5. 优化思考过程解析逻辑:只要配置了模型支持思考,均会解析 标签,不会因为对话时,关闭思考而不解析。 ## 🐛 修复 diff --git a/packages/service/core/ai/utils.ts b/packages/service/core/ai/utils.ts index a35e164c9..43fdda3bb 100644 --- a/packages/service/core/ai/utils.ts +++ b/packages/service/core/ai/utils.ts @@ -132,7 +132,7 @@ export const parseReasoningStreamContent = () => { let endTagBuffer = ''; /* - parseReasoning - 只控制是否主动解析 ,如果接口已经解析了,仍然会返回 think 内容。 + parseThinkTag - 只控制是否主动解析 ,如果接口已经解析了,则不再解析。 */ const parsePart = ( part: { @@ -143,13 +143,13 @@ export const parseReasoningStreamContent = () => { }; }[]; }, - parseReasoning = false + parseThinkTag = false ): [string, string] => { const content = part.choices?.[0]?.delta?.content || ''; // @ts-ignore const reasoningContent = part.choices?.[0]?.delta?.reasoning_content || ''; - if (reasoningContent || !parseReasoning) { + if (reasoningContent || !parseThinkTag) { isInThinkTag = false; return [reasoningContent, content]; } diff --git a/packages/service/core/workflow/dispatch/chat/oneapi.ts b/packages/service/core/workflow/dispatch/chat/oneapi.ts index d5bcd4939..2e0abebb3 100644 --- a/packages/service/core/workflow/dispatch/chat/oneapi.ts +++ b/packages/service/core/workflow/dispatch/chat/oneapi.ts @@ -208,6 +208,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise