From 3a97f75a5c56d00031f0f5fc57668bf4f62f96d9 Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Thu, 13 Jun 2024 15:48:05 +0100 Subject: [PATCH] Fix generate_content result parsing `generate_content()` was parsing the reqwest result to `GenerateContentResponseResult` instead of `GenerateContentResponse`, causing error responses to be handled incorrectly. This is fixed by ensuring the result string is parsed into the correct type. --- src/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index ebd6f0a..d69d61c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -137,8 +137,8 @@ impl GeminiClient { let txt_json = resp.text().await?; tracing::debug!("generate_content response: {:?}", txt_json); - match serde_json::from_str(&txt_json) { - Ok(response) => Ok(response), + match serde_json::from_str::(&txt_json) { + Ok(response) => Ok(response.into_result()?), Err(e) => { tracing::error!("Failed to parse response: {} with error {}", txt_json, e); Err(e.into())