mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 21:40:41 +01:00
google_ai: Default citation_sources when Gemini omits it (#67474)
Last night Gemini models kept failing right before they finished. A chunk carried `citationMetadata` without `citationSources`, deserializing `CitationMetadata` failed, and the response was treated as a failure. The hosted path is fixed in Cloud; this PR adds the same default to the field in Zed's client, so requests made directly to the Gemini API don't fail the same way. Release Notes: - Fixed Gemini responses failing when they included citation metadata without citation sources.
This commit is contained in:
@@ -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<CitationSource>,
|
||||
}
|
||||
|
||||
@@ -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<ErrorKind>) -> LanguageModelCompletionError {
|
||||
futures::executor::block_on(async {
|
||||
let client = FakeHttpClient::create(move |_| async move {
|
||||
|
||||
Reference in New Issue
Block a user