feat: add SSE streaming, thinking models, and modernized Part struct
Some checks failed
Rust / build (push) Has been cancelled
Some checks failed
Rust / build (push) Has been cancelled
This commit is contained in:
@@ -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()
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user