use adk_gemini::{Gemini, Tool};
use display_error_chain::DisplayErrorChain;
use std::env;
use std::process::ExitCode;
use tracing::info;
#[tokio::main]
async fn main() -> ExitCode {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing::level_filters::LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();
match do_main().await {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
let error_chain = DisplayErrorChain::new(e.as_ref());
tracing::error!(error.debug = ?e, error.chained = %error_chain, "execution failed");
ExitCode::FAILURE
}
}
}
async fn do_main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY environment variable not set");
let client = Gemini::new(api_key).expect("unable to create Gemini API client");
info!("starting url context tool example");
let url_context_tool = Tool::url_context();
info!("example 1: analyzing news article content");
let response1 = client
.generate_content()
.with_user_message("Please summarize the main points from this article: https://blog.google/technology/ai/google-gemini-ai/")
.with_tool(url_context_tool.clone())
.execute()
.await?;
info!(response = response1.text(), "news article analysis completed");
info!("example 2: extracting documentation information");
let response2 = client
.generate_content()
.with_user_message(
"What are the key features mentioned on this page: https://docs.rs/tokio/latest/tokio/",
)
.with_tool(url_context_tool.clone())
.execute()
.await?;
info!(response = response2.text(), "documentation analysis completed");
info!("example 3: comparing content from multiple sources");
let response3 = client
.generate_content()
.with_user_message(
"Compare the features described on these two pages: \
https://www.rust-lang.org/learn and https://go.dev/learn. \
What are the similarities and differences in their learning approaches?",
)
.with_tool(url_context_tool.clone())
.execute()
.await?;
info!(response = response3.text(), "content comparison completed");
info!("example 4: fact checking with url context");
let response4 = client
.generate_content()
.with_user_message(
"Based on the information from https://www.who.int/news-room/fact-sheets, \
can you verify claims about global health statistics and provide accurate data?",
)
.with_tool(url_context_tool.clone())
.execute()
.await?;
info!(response = response4.text(), "fact checking completed");
info!("example 5: research synthesis from academic source");
let response5 = client
.generate_content()
.with_user_message(
"Please read this research paper abstract and methodology section: \
https://arxiv.org/abs/2103.00020 and explain the key findings in simple terms.",
)
.with_tool(url_context_tool)
.execute()
.await?;
info!(response = response5.text(), "research synthesis completed");
Ok(())
}