fix(tui): guard reasoning_content behind provider check to prevent TUI display corruption from third-party APIs#1680
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces logic to differentiate how various API providers handle reasoning_content in streaming deltas, specifically addressing third-party proxies that use this field for standard response text. Feedback includes a request to add NvidiaNim to the list of supported reasoning providers to avoid regressions, a suggestion to refine the tool call detection by checking for non-empty arrays rather than just the presence of the field, and a recommendation to adjust the fallback logic to prevent potential data loss when both reasoning and tool calls are present in the same chunk.
64084fe to
0316407
Compare
…I display corruption from third-party APIs (Hmbown#1673)
0316407 to
b5bf0a5
Compare
|
Thanks for the provider-gated reasoning_content fix. The scoped behavior was harvested into v0.8.39 via #1734 and credited in the changelog, so I am closing this PR to keep the queue clean. If a generic OpenAI-compatible provider still renders answer text as repeated thinking blocks on latest, please reopen with the provider/model and one raw SSE chunk. |
Problem
When using a third-party OpenAI-compatible API provider that returns
reasoning_contentfields in streaming SSE chunks, deepseek-tui incorrectly treats every token as a separate "thinking" block instead of normal text output. This causes severe display corruption where each character/token is rendered with its ownthinking done · 0.0sheader.Fixes #1673
Root Cause
is_reasoning_model()checks only the model name (e.g.,deepseek-v4-pro,deepseek-v4-flash) to decide whetherreasoning_contentdeltas should be treated as thinking blocks — it does not consider whether the current provider actually supports reasoning content semantics.When a non-DeepSeek provider streams
reasoning_contentfields alongside normal response text, every chunk triggers the thinking UI path, corrupting the display.Fix
requires_reasoning_content()helper that returnstrueonly for the native DeepSeek provider (ProviderKind::Deepseek).handle_chat_completion_stream()to userequires_reasoning_content(api_provider)instead ofis_reasoning_model(model)when deciding whether to emitStreamEvent::ReasoningDelta.parse_sse_chunk()to accept the provider kind and use the same gate.This ensures third-party OpenAI-compatible providers that happen to serve DeepSeek models are not incorrectly treated as supporting DeepSeek's reasoning content protocol, while preserving full native DeepSeek reasoning display.