thinking_curl_equivalent/
thinking_curl_equivalent.rs1use gemini_rust::{Gemini, GenerationConfig, ThinkingConfig};
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").expect("GEMINI_API_KEY environment variable not set");
8
9 let client = Gemini::with_model(api_key, "models/gemini-2.5-pro".to_string());
34
35 println!("=== Thinking Curl Equivalent Example ===\n");
36
37 println!("--- Method 1: Using high-level API ---");
39
40 let response1 = client
41 .generate_content()
42 .with_user_message(
43 "Provide a list of the top 3 famous physicists and their major contributions",
44 )
45 .with_thinking_budget(1024)
46 .with_thoughts_included(true)
47 .execute()
48 .await?;
49
50 let thoughts1 = response1.thoughts();
52 if !thoughts1.is_empty() {
53 println!("Thinking summary:");
54 for (i, thought) in thoughts1.iter().enumerate() {
55 println!("Thought {}: {}\n", i + 1, thought);
56 }
57 }
58
59 println!("Answer: {}\n", response1.text());
60
61 println!("--- Method 2: Fully matching curl example structure ---");
63
64 let thinking_config = ThinkingConfig {
65 thinking_budget: Some(1024),
66 include_thoughts: Some(true),
67 };
68
69 let generation_config = GenerationConfig {
70 thinking_config: Some(thinking_config),
71 ..Default::default()
72 };
73
74 let response2 = client
75 .generate_content()
76 .with_user_message(
77 "Provide a list of the top 3 famous physicists and their major contributions",
78 )
79 .with_generation_config(generation_config)
80 .execute()
81 .await?;
82
83 let thoughts2 = response2.thoughts();
85 if !thoughts2.is_empty() {
86 println!("Thinking summary:");
87 for (i, thought) in thoughts2.iter().enumerate() {
88 println!("Thought {}: {}\n", i + 1, thought);
89 }
90 }
91
92 println!("Answer: {}\n", response2.text());
93
94 if let Some(usage) = &response2.usage_metadata {
96 println!("Token usage:");
97 println!(" Prompt tokens: {}", usage.prompt_token_count);
98 println!(
99 " Response tokens: {}",
100 usage.candidates_token_count.unwrap_or(0)
101 );
102 if let Some(thinking_tokens) = usage.thoughts_token_count {
103 println!(" Thinking tokens: {}", thinking_tokens);
104 }
105 println!(" Total tokens: {}", usage.total_token_count);
106 }
107
108 println!("\n--- Method 3: Different thinking budget comparison ---");
110
111 println!("Thinking disabled:");
113 let response_no_thinking = client
114 .generate_content()
115 .with_user_message("Explain the basic principles of quantum mechanics")
116 .execute()
117 .await?;
118 println!("Answer: {}\n", response_no_thinking.text());
119
120 println!("Dynamic thinking:");
122 let response_dynamic = client
123 .generate_content()
124 .with_user_message("Explain the basic principles of quantum mechanics")
125 .with_dynamic_thinking()
126 .with_thoughts_included(true)
127 .execute()
128 .await?;
129
130 let thoughts_dynamic = response_dynamic.thoughts();
131 if !thoughts_dynamic.is_empty() {
132 println!("Thinking summary:");
133 for (i, thought) in thoughts_dynamic.iter().enumerate() {
134 println!("Thought {}: {}\n", i + 1, thought);
135 }
136 }
137 println!("Answer: {}\n", response_dynamic.text());
138
139 println!("High thinking budget (4096 tokens):");
141 let response_high_budget = client
142 .generate_content()
143 .with_user_message("Explain the basic principles of quantum mechanics")
144 .with_thinking_budget(4096)
145 .with_thoughts_included(true)
146 .execute()
147 .await?;
148
149 let thoughts_high = response_high_budget.thoughts();
150 if !thoughts_high.is_empty() {
151 println!("Thinking summary:");
152 for (i, thought) in thoughts_high.iter().enumerate() {
153 println!("Thought {}: {}\n", i + 1, thought);
154 }
155 }
156 println!("Answer: {}", response_high_budget.text());
157
158 Ok(())
159}