generation_config/
generation_config.rs1use gemini_rust::{Gemini, GenerationConfig};
2use std::env;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let api_key = env::var("GEMINI_API_KEY")
8 .expect("GEMINI_API_KEY environment variable not set");
9
10 let client = Gemini::new(api_key);
12
13 println!("--- Using full generation config ---");
15 let response1 = client
16 .generate_content()
17 .with_system_prompt("You are a helpful assistant.")
18 .with_user_message("Write a short poem about Rust programming language.")
19 .with_generation_config(
20 GenerationConfig {
21 temperature: Some(0.9),
22 top_p: Some(0.8),
23 top_k: Some(20),
24 max_output_tokens: Some(200),
25 candidate_count: Some(1),
26 stop_sequences: Some(vec!["END".to_string()]),
27 response_mime_type: None,
28 response_schema: None,
29 }
30 )
31 .execute()
32 .await?;
33
34 println!("Response with high temperature (0.9):\n{}\n", response1.text());
35
36 println!("--- Using individual generation parameters ---");
38 let response2 = client
39 .generate_content()
40 .with_system_prompt("You are a helpful assistant.")
41 .with_user_message("Write a short poem about Rust programming language.")
42 .with_temperature(0.2)
43 .with_max_output_tokens(100)
44 .execute()
45 .await?;
46
47 println!("Response with low temperature (0.2):\n{}\n", response2.text());
48
49 println!("--- Setting multiple parameters individually ---");
51 let response3 = client
52 .generate_content()
53 .with_system_prompt("You are a helpful assistant.")
54 .with_user_message("List 3 benefits of using Rust.")
55 .with_temperature(0.7)
56 .with_top_p(0.9)
57 .with_max_output_tokens(150)
58 .with_stop_sequences(vec!["4.".to_string()])
59 .execute()
60 .await?;
61
62 println!("Response with custom parameters and stop sequence:\n{}", response3.text());
63
64 Ok(())
65}