-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathagent.rs
35 lines (30 loc) · 1.02 KB
/
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
use std::sync::Arc;
use langchain_rust::{
agent::{AgentExecutor, ConversationalAgentBuilder},
chain::{options::ChainCallOptions, Chain},
llm::openai::{OpenAI, OpenAIModel},
memory::SimpleMemory,
prompt_args,
tools::CommandExecutor,
};
#[tokio::main]
async fn main() {
let llm = OpenAI::default().with_model(OpenAIModel::Gpt4Turbo);
let memory = SimpleMemory::new();
let command_executor = CommandExecutor::default();
let agent = ConversationalAgentBuilder::new()
.tools(&[Arc::new(command_executor)])
.options(ChainCallOptions::new().with_max_tokens(1000))
.build(llm)
.unwrap();
let executor = AgentExecutor::from_agent(agent).with_memory(memory.into());
let input_variables = prompt_args! {
"input" => "What is the name of the current dir",
};
match executor.invoke(input_variables).await {
Ok(result) => {
println!("Result: {:?}", result);
}
Err(e) => panic!("Error invoking LLMChain: {:?}", e),
}
}