feat: add SSE streaming, thinking models, and modernized Part struct
Some checks failed
Rust / build (push) Has been cancelled

This commit is contained in:
2026-09-20 16:42:55 +01:00
parent ad82fc712b
commit 494aab6d14
18 changed files with 703 additions and 696 deletions

View File

@@ -1,9 +1,8 @@
use std::{error::Error, io::Cursor};
use gemini_rs::prelude::{
GeminiClient, PersonGeneration, PredictImageRequest, PredictImageRequestParameters,
GeminiClient, PredictImageRequest, PredictImageRequestParameters,
PredictImageRequestParametersOutputOptions, PredictImageRequestPrompt,
PredictImageSafetySetting,
};
use image::{ImageFormat, ImageReader};
@@ -35,8 +34,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
mime_type: Some("image/jpeg".to_string()),
compression_quality: Some(75),
}),
person_generation: Some(PersonGeneration::AllowAll),
safety_setting: Some(PredictImageSafetySetting::BlockOnlyHigh),
person_generation: Some("allow_all".to_string()),
safety_setting: Some("block_only_high".to_string()),
..Default::default()
},
};

View File

@@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let request = GenerateContentRequest {
contents: vec![Content {
role: Some(Role::User),
parts: Some(vec![Part::Text(prompt.to_string())]),
parts: Some(vec![Part::text(prompt)]),
}],
tools: Some(vec![Tools {
google_search_retrieval: Some(GoogleSearchRetrieval::default()),

View File

@@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let request = GenerateContentRequest {
contents: vec![Content {
role: Some(Role::User),
parts: Some(vec![Part::Text(prompt.to_string())]),
parts: Some(vec![Part::text(prompt)]),
}],
tools: Some(vec![Tools {
google_search: Some(GoogleSearch::default()),

View File

@@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let request = GenerateContentRequest {
contents: vec![Content {
role: Some(Role::User),
parts: Some(vec![Part::Text(prompt.to_string())]),
parts: Some(vec![Part::text(prompt)]),
}],
generation_config: Some(GenerationConfig {
response_mime_type: Some("application/json".to_string()),

View File

@@ -21,7 +21,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let request = GenerateContentRequest {
contents: vec![Content {
role: Some(Role::User),
parts: Some(vec![Part::Text(prompt.to_string())]),
parts: Some(vec![Part::text(prompt)]),
}],
safety_settings: Some(vec![SafetySetting {
category: HarmCategory::HateSpeech,

View File

@@ -23,11 +23,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let request = GenerateContentRequest::builder().contents(prompt).build();
let mut queue = gemini
.generate_content_stream(&request, "gemini-2.0-flash-001")
.stream_generate_content(&request, "gemini-2.0-flash-001")
.await?;
while let Some(Ok(response)) = queue.next().await {
println!("Response: {:?}", response);
while let Some(response) = queue.next().await {
println!("Response: {:?}", response?);
}
Ok(())