Adds error logging when failing o parse response
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use std::{error::Error, io::Cursor};
|
||||
|
||||
use gemini_rs::prelude::{
|
||||
GeminiClient, PredictImageRequest, PredictImageRequestParameters, PredictImageRequestPrompt,
|
||||
GeminiClient, PredictImageRequest, PredictImageRequestParameters,
|
||||
PredictImageRequestParametersOutputOptions, PredictImageRequestPrompt,
|
||||
};
|
||||
use image::{ImageFormat, ImageReader};
|
||||
|
||||
@@ -28,6 +29,11 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
||||
}],
|
||||
parameters: PredictImageRequestParameters {
|
||||
sample_count: 1,
|
||||
aspect_ratio: Some("1:1".to_string()),
|
||||
output_options: Some(PredictImageRequestParametersOutputOptions {
|
||||
mime_type: Some("image/jpeg".to_string()),
|
||||
compression_quality: Some(75),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||
use deadqueue::unlimited::Queue;
|
||||
use futures_util::stream::StreamExt;
|
||||
use reqwest_eventsource::{Event, EventSource};
|
||||
use tracing::error;
|
||||
|
||||
use crate::dialogue::{Message, Role};
|
||||
use crate::error::{Error, Result};
|
||||
@@ -274,6 +275,13 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
|
||||
.await?;
|
||||
|
||||
let txt_json = resp.text().await?;
|
||||
Ok(serde_json::from_str(&txt_json)?)
|
||||
|
||||
match serde_json::from_str::<PredictImageResponse>(&txt_json) {
|
||||
Ok(response) => return Ok(response),
|
||||
Err(e) => {
|
||||
error!(response = txt_json, error = ?e, "Failed to parse response");
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ pub struct PredictImageRequestParameters {
|
||||
/// - "watercolor"
|
||||
/// - "cyberpunk"
|
||||
/// - "pop_art"
|
||||
/// Pre-defined styles is only supported for model imagegeneration@002
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sample_image_style: Option<String>,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user