Fix error when deserializing Gemini streams (#29470)
Sometimes Gemini would report `Content` without a `parts` field. Release Notes: - Fixed a bug that would sometimes cause Gemini models to fail streaming their response.
This commit is contained in:
parent
f2b4004c00
commit
3fdbc3090d
1 changed files with 5 additions and 1 deletions
|
@ -48,7 +48,10 @@ pub async fn stream_generate_content(
|
||||||
if let Some(line) = line.strip_prefix("data: ") {
|
if let Some(line) = line.strip_prefix("data: ") {
|
||||||
match serde_json::from_str(line) {
|
match serde_json::from_str(line) {
|
||||||
Ok(response) => Some(Ok(response)),
|
Ok(response) => Some(Ok(response)),
|
||||||
Err(error) => Some(Err(anyhow!(error))),
|
Err(error) => Some(Err(anyhow!(format!(
|
||||||
|
"Error parsing JSON: {:?}\n{:?}",
|
||||||
|
error, line
|
||||||
|
)))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -152,6 +155,7 @@ pub struct GenerateContentCandidate {
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
|
#[serde(default)]
|
||||||
pub parts: Vec<Part>,
|
pub parts: Vec<Part>,
|
||||||
pub role: Role,
|
pub role: Role,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue