Merge pull request #32 from Zhou-Ruichen/fix/suppress-duplicated-reasoning-content

fix(chatFormats): suppress content when it duplicates reasoning_content
This commit is contained in:
Cita
2026-03-06 18:41:48 +08:00
committed by GitHub
+9 -1
View File
@@ -736,7 +736,7 @@ export function normalizeUpstreamStreamEvent(
const delta = isRecord(choice?.delta) ? choice.delta : {};
const deltaParsed = extractTextAndReasoning(delta.content ?? delta);
const contentDelta =
const rawContentDelta =
deltaParsed.content
|| (typeof choice?.message?.content === 'string' ? choice.message.content : '')
|| '';
@@ -747,6 +747,14 @@ export function normalizeUpstreamStreamEvent(
|| deltaParsed.reasoning
|| '';
// Some upstream providers (e.g. certain OpenAI-compatible aggregators) emit thinking
// tokens with the same text duplicated in both delta.content and delta.reasoning_content.
// When the two values are identical it means content is just echoing the reasoning —
// suppress it so internal thinking is never leaked to downstream consumers.
const contentDelta = (reasoningDelta && rawContentDelta === reasoningDelta)
? ''
: rawContentDelta;
const rawToolCalls = Array.isArray((delta as any).tool_calls)
? ((delta as any).tool_calls as unknown[])
: [];