Skip to main content

thinking/
thinking.rs

1use gemini_client_api::gemini::ask::Gemini;
2use gemini_client_api::gemini::types::request::ThinkingConfig;
3use gemini_client_api::gemini::types::sessions::Session;
4use std::env;
5
6#[tokio::main]
7async fn main() {
8    let mut session = Session::new(4);
9    let api_key = env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY must be set");
10    
11    // Note: Thinking mode requires a supported model like gemini-2.0-flash-thinking-exp
12    let ai = Gemini::new(api_key, "gemini-2.0-flash-thinking-exp", None)
13        .set_thinking_config(ThinkingConfig::new(true, 1024));
14
15    println!("--- Thinking Mode Example ---");
16    let prompt = "How many 'r's are in the word strawberry? Think step by step.";
17    println!("User: {}\n", prompt);
18
19    let response = ai.ask(session.ask_string(prompt)).await.unwrap();
20
21    // Show the "thoughts" part separately
22    let thoughts = response.get_chat().get_thoughts("\n");
23    if !thoughts.is_empty() {
24        println!("--- Gemini's Thoughts ---\n{}\n", thoughts);
25    }
26
27    // Show the final answer
28    let answer = response.get_chat().get_text_no_think("");
29    println!("--- Gemini's Answer ---\n{}", answer);
30}