Skip to content
Open
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
24 changes: 9 additions & 15 deletions crates/mofa-foundation/src/llm/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,15 @@ fn parse_gemini_sse(resp: reqwest::Response, model: String) -> ChatStream {
}
Ok(None) => {
// End of stream. If there is leftover data, try to parse it.
if !buf.trim().is_empty() {
if let Some(json_str) = buf.trim().strip_prefix("data: ") {
if json_str.trim() != "[DONE]" {
if let Ok(chunk) =
serde_json::from_str::<GeminiStreamChunk>(json_str)
{
let completion =
gemini_chunk_to_completion(&chunk, &model, is_first);
return Some((
Ok(completion),
(resp, String::new(), model, false),
));
}
}
}
if let Some(json_str) = buf.trim().strip_prefix("data: ")
&& json_str.trim() != "[DONE]"
&& let Ok(chunk) = serde_json::from_str::<GeminiStreamChunk>(json_str)
{
let completion = gemini_chunk_to_completion(&chunk, &model, is_first);
return Some((
Ok(completion),
(resp, String::new(), model, false),
));
}
return None;
}
Expand Down
Loading