Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/llm/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,10 @@ fn parse_openai_reasoning_fallback(message: &serde_json::Value) -> Option<String
fn collect_openai_text_content(value: &serde_json::Value, text_parts: &mut Vec<String>) {
match value {
serde_json::Value::String(text) => {
if !text.trim().is_empty() {
// Use is_empty() instead of trim().is_empty() to preserve whitespace-only
// segments. Streaming providers (e.g. Kimi) sometimes send content chunks
// that are just spaces; dropping those causes missing spaces in output.
if !text.is_empty() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that whitespace-only chunks count as “present”, the higher-level is_empty() checks can be fooled by an all-whitespace response (e.g. a single " ") and skip the “empty response” error path.

Might be worth adding an overall trim().is_empty() guard at the point you decide “empty response” (while still keeping internal whitespace between chunks), plus a small regression test for "Hello" + " " + "world".

text_parts.push(text.to_string());
}
}
Expand All @@ -2579,17 +2582,17 @@ fn collect_openai_text_content(value: &serde_json::Value, text_parts: &mut Vec<S
}
serde_json::Value::Object(map) => {
if let Some(text) = map.get("text").and_then(serde_json::Value::as_str)
&& !text.trim().is_empty()
&& !text.is_empty()
{
text_parts.push(text.to_string());
}
if let Some(summary) = map.get("summary").and_then(serde_json::Value::as_str)
&& !summary.trim().is_empty()
&& !summary.is_empty()
{
text_parts.push(summary.to_string());
}
if let Some(refusal) = map.get("refusal").and_then(serde_json::Value::as_str)
&& !refusal.trim().is_empty()
&& !refusal.is_empty()
{
text_parts.push(refusal.to_string());
}
Expand Down Expand Up @@ -2663,7 +2666,7 @@ fn extract_text_content_from_responses_output_item(
}

if let Some(text) = map.get("text").and_then(serde_json::Value::as_str)
&& !text.trim().is_empty()
&& !text.is_empty()
{
text_parts.push(text.to_string());
}
Expand Down
Loading