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.
This commit is contained in:
2024-06-13 15:48:05 +01:00
parent c4e9f78ec9
commit 3a97f75a5c

View File

@@ -137,8 +137,8 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
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::<GenerateContentResponse>(&txt_json) {
Ok(response) => Ok(response.into_result()?),
Err(e) => {
tracing::error!("Failed to parse response: {} with error {}", txt_json, e);
Err(e.into())