use gemini_rs::types::{FunctionDeclaration, Tools};
use serde_json::json;
#[tokio::main]
async fn main() {
let function_decs = vec![FunctionDeclaration {
name: "set_theme".to_string(),
description: "Set the theme of the application".to_string(),
parameters: json!({
"type": "object",
"properties": {
"theme": {
"type": "string",
"description": "The theme to set",
"enum": ["light", "dark"]
}
},
"required": ["theme"]
}),
}];
let tools = vec![Tools {
function_declarations: Some(function_decs),
google_search: None,
code_execution: None,
}];
let client = gemini_rs::Client::instance();
let mut req = client.generate_content("gemini-2.0-flash");
req.tools(tools);
req.message("Set the theme to dark.");
let response = req.await;
match response {
Ok(resp) => match &resp.candidates[0].content.parts[0].function_call {
Some(func) => set_theme(func.args["theme"].as_str().unwrap()),
None => eprint!("Function not called"),
},
Err(e) => eprintln!("Error: {e}"),
}
}
fn set_theme(theme: &str) {
println!("Setting application theme to {}", theme);
}