diff --git a/crates/google_ai/src/google_ai.rs b/crates/google_ai/src/google_ai.rs index f2edaad6a7c..c52429cb89f 100644 --- a/crates/google_ai/src/google_ai.rs +++ b/crates/google_ai/src/google_ai.rs @@ -742,6 +742,8 @@ pub struct CitationSource { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CitationMetadata { + /// Omitted by the API when empty. + #[serde(default)] pub citation_sources: Vec, } @@ -1135,6 +1137,27 @@ mod tests { )); } + #[test] + fn citation_metadata_without_sources_deserializes() { + let response: GenerateContentResponse = serde_json::from_value(json!({ + "candidates": [{ + "content": {"role": "model", "parts": [{"text": "Done"}]}, + "finishReason": "STOP", + "citationMetadata": {} + }] + })) + .unwrap(); + let candidate = &response.candidates.unwrap()[0]; + assert!( + candidate + .citation_metadata + .as_ref() + .unwrap() + .citation_sources + .is_empty() + ); + } + fn completion_error(read_error: Option) -> LanguageModelCompletionError { futures::executor::block_on(async { let client = FakeHttpClient::create(move |_| async move {