forked from sobelio/llm-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_invocation.rs
50 lines (41 loc) · 1.44 KB
/
simple_invocation.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
50
use llm_chain::executor;
use llm_chain::parameters;
use llm_chain::prompt::{ConversationTemplate, StringTemplate};
use llm_chain::step::Step;
use llm_chain::tools::tools::BashTool;
use llm_chain::tools::ToolCollection;
// A simple example generating a prompt with some tools.
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let exec = executor!()?;
let mut tool_collection = ToolCollection::new();
tool_collection.add_tool(BashTool::new());
let template = StringTemplate::combine(vec![
tool_collection.to_prompt_template().unwrap(),
StringTemplate::tera("Please perform the following task: {{task}}."),
]);
let task = "Find the file GOAL.txt and tell me its content";
let prompt = ConversationTemplate::new()
.with_system_template(
"You are an automated agent for performing tasks. Your output must always be YAML.",
)
.with_user(template);
let result = Step::for_prompt_template(prompt.into())
.run(¶meters!("task" => task), &exec)
.await?;
println!("{}", result);
match tool_collection
.process_chat_input(
&result
.to_immediate()
.await?
.primary_textual_output()
.unwrap(),
)
.await
{
Ok(output) => println!("{}", output),
Err(e) => println!("Error: {}", e),
}
Ok(())
}