Skip to content
Closed
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
17 changes: 4 additions & 13 deletions src/openai_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ pub async fn chat_completions(
finish_reason: None,
}],
};
let _ = tx_tokens.send(format!(
"data: {}\n\n",
serde_json::to_string(&initial_chunk).unwrap()
));
let _ = tx_tokens.send(serde_json::to_string(&initial_chunk).unwrap());
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

The SSE format requires 'data: ' prefix and double newlines for proper client parsing. Removing these breaks SSE protocol compliance. The format should be 'data: {json}\n\n' for each event.

Copilot uses AI. Check for mistakes.


// Generate and stream tokens
let _ = loaded
Expand All @@ -243,10 +240,7 @@ pub async fn chat_completions(
finish_reason: None,
}],
};
let _ = tx_tokens.send(format!(
"data: {}\n\n",
serde_json::to_string(&chunk).unwrap()
));
let _ = tx_tokens.send(serde_json::to_string(&chunk).unwrap());
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

Token chunks must follow SSE format with 'data: ' prefix and proper line endings. Raw JSON strings without SSE formatting will not be parsed correctly by SSE clients.

Copilot uses AI. Check for mistakes.

})),
)
.await;
Expand All @@ -266,11 +260,8 @@ pub async fn chat_completions(
finish_reason: Some("stop".to_string()),
}],
};
let _ = tx.send(format!(
"data: {}\n\n",
serde_json::to_string(&final_chunk).unwrap()
));
let _ = tx.send("data: [DONE]\n\n".to_string());
let _ = tx.send(serde_json::to_string(&final_chunk).unwrap());
let _ = tx.send("[DONE]".to_string());
Comment on lines +263 to +264
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

Both the final chunk and [DONE] sentinel need proper SSE formatting. They should be 'data: {json}\n\n' and 'data: [DONE]\n\n' respectively to maintain SSE protocol compliance.

Copilot uses AI. Check for mistakes.

});

let stream = UnboundedReceiverStream::new(rx)
Expand Down
Loading