-
-
Notifications
You must be signed in to change notification settings - Fork 214
fix: remove extraneous data:
from streaming responses
#49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
|
||
// Generate and stream tokens | ||
let _ = loaded | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
})), | ||
) | ||
.await; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
}); | ||
|
||
let stream = UnboundedReceiverStream::new(rx) | ||
|
There was a problem hiding this comment.
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.