-
Notifications
You must be signed in to change notification settings - Fork 140
/
gemini_agent.rs
49 lines (41 loc) · 1.47 KB
/
gemini_agent.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use rig::{
completion::Prompt,
providers::gemini::{self, completion::gemini_api_types::GenerationConfig},
};
#[tracing::instrument(ret)]
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_target(false)
.init();
// Initialize the Google Gemini client
let client = gemini::Client::from_env();
// Create agent with a single context prompt
let agent = client
.agent(gemini::completion::GEMINI_1_5_PRO)
.preamble("Be creative and concise. Answer directly and clearly.")
.temperature(0.5)
// The `GenerationConfig` utility struct helps construct a typesafe `additional_params`
.additional_params(serde_json::to_value(GenerationConfig {
top_k: Some(1),
top_p: Some(0.95),
candidate_count: Some(1),
..Default::default()
})?) // Unwrap the Result to get the Value
.build();
tracing::info!("Prompting the agent...");
// Prompt the agent and print the response
let response = agent
.prompt("How much wood would a woodchuck chuck if a woodchuck could chuck wood? Infer an answer.")
.await;
tracing::info!("Response: {:?}", response);
match response {
Ok(response) => println!("{}", response),
Err(e) => {
tracing::error!("Error: {:?}", e);
return Err(e.into());
}
}
Ok(())
}