perf: think tag parse (#4102)
This commit is contained in:
parent
75e671bb43
commit
4655c2754e
@ -17,6 +17,7 @@ weight: 799
|
|||||||
2. 应用拉取绑定知识库数据交由后端处理。
|
2. 应用拉取绑定知识库数据交由后端处理。
|
||||||
3. 增加依赖包安全版本检测,并升级部分依赖包。
|
3. 增加依赖包安全版本检测,并升级部分依赖包。
|
||||||
4. 模型测试代码。
|
4. 模型测试代码。
|
||||||
|
5. 优化思考过程解析逻辑:只要配置了模型支持思考,均会解析 <think> 标签,不会因为对话时,关闭思考而不解析。
|
||||||
|
|
||||||
## 🐛 修复
|
## 🐛 修复
|
||||||
|
|
||||||
|
|||||||
@ -132,7 +132,7 @@ export const parseReasoningStreamContent = () => {
|
|||||||
let endTagBuffer = '';
|
let endTagBuffer = '';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
parseReasoning - 只控制是否主动解析 <think></think>,如果接口已经解析了,仍然会返回 think 内容。
|
parseThinkTag - 只控制是否主动解析 <think></think>,如果接口已经解析了,则不再解析。
|
||||||
*/
|
*/
|
||||||
const parsePart = (
|
const parsePart = (
|
||||||
part: {
|
part: {
|
||||||
@ -143,13 +143,13 @@ export const parseReasoningStreamContent = () => {
|
|||||||
};
|
};
|
||||||
}[];
|
}[];
|
||||||
},
|
},
|
||||||
parseReasoning = false
|
parseThinkTag = false
|
||||||
): [string, string] => {
|
): [string, string] => {
|
||||||
const content = part.choices?.[0]?.delta?.content || '';
|
const content = part.choices?.[0]?.delta?.content || '';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const reasoningContent = part.choices?.[0]?.delta?.reasoning_content || '';
|
const reasoningContent = part.choices?.[0]?.delta?.reasoning_content || '';
|
||||||
if (reasoningContent || !parseReasoning) {
|
if (reasoningContent || !parseThinkTag) {
|
||||||
isInThinkTag = false;
|
isInThinkTag = false;
|
||||||
return [reasoningContent, content];
|
return [reasoningContent, content];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -208,6 +208,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
|||||||
res,
|
res,
|
||||||
stream: response,
|
stream: response,
|
||||||
aiChatReasoning,
|
aiChatReasoning,
|
||||||
|
parseThinkTag: modelConstantsData.reasoning,
|
||||||
isResponseAnswerText,
|
isResponseAnswerText,
|
||||||
workflowStreamResponse
|
workflowStreamResponse
|
||||||
});
|
});
|
||||||
@ -513,12 +514,14 @@ async function streamResponse({
|
|||||||
stream,
|
stream,
|
||||||
workflowStreamResponse,
|
workflowStreamResponse,
|
||||||
aiChatReasoning,
|
aiChatReasoning,
|
||||||
|
parseThinkTag,
|
||||||
isResponseAnswerText
|
isResponseAnswerText
|
||||||
}: {
|
}: {
|
||||||
res: NextApiResponse;
|
res: NextApiResponse;
|
||||||
stream: StreamChatType;
|
stream: StreamChatType;
|
||||||
workflowStreamResponse?: WorkflowResponseType;
|
workflowStreamResponse?: WorkflowResponseType;
|
||||||
aiChatReasoning?: boolean;
|
aiChatReasoning?: boolean;
|
||||||
|
parseThinkTag?: boolean;
|
||||||
isResponseAnswerText?: boolean;
|
isResponseAnswerText?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const write = responseWriteController({
|
const write = responseWriteController({
|
||||||
@ -535,7 +538,7 @@ async function streamResponse({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [reasoningContent, content] = parsePart(part, aiChatReasoning);
|
const [reasoningContent, content] = parsePart(part, parseThinkTag);
|
||||||
answer += content;
|
answer += content;
|
||||||
reasoning += reasoningContent;
|
reasoning += reasoningContent;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user