forked from sobelio/llm-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself_ask_with_search.rs
32 lines (31 loc) · 933 Bytes
/
self_ask_with_search.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
use llm_chain::{
agents::self_ask_with_search::{Agent, EarlyStoppingConfig},
executor,
tools::tools::BingSearch,
};
#[tokio::main(flavor = "current_thread")]
async fn main() {
let executor = executor!().unwrap();
let bing_api_key = std::env::var("BING_API_KEY").unwrap();
let search_tool = BingSearch::new(bing_api_key);
let agent = Agent::new(
executor,
search_tool,
EarlyStoppingConfig {
max_iterations: Some(10),
max_time_elapsed_seconds: Some(30.0),
},
);
let (res, intermediate_steps) = agent
.run("What is the capital of the birthplace of Levy Mwanawasa?")
.await
.unwrap();
println!(
"Are followup questions needed here: {}",
agent.build_agent_scratchpad(&intermediate_steps)
);
println!(
"Agent final answer: {}",
res.return_values.get("output").unwrap()
);
}