pub fn get_tools(api_key: &str) -> (SearchTools, CallTool)
Expand description
Returns two essential tools to integrate Unifai with your agent.
Examples found in repository?
examples/openai_agent.rs (line 17)
14async fn main() {
15 let unifai_agent_api_key =
16 env::var("UNIFAI_AGENT_API_KEY").expect("UNIFAI_AGENT_API_KEY not set");
17 let (search_tools, call_tool) = get_tools(&unifai_agent_api_key);
18
19 let openai_api_key = env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
20 let openai_client = openai::Client::new(&openai_api_key);
21 let agent = openai_client
22 .agent(openai::GPT_4O)
23 .preamble(concat!(
24 "You are a personal assistant capable of doing many things with your tools. ",
25 "When you are given a task you cannot do (like something you don't know, ",
26 "or requires you to take some action), try find appropriate tools to do it."
27 ))
28 .tool(search_tools)
29 .tool(call_tool)
30 .build();
31
32 let prompt = "Get the balance of Solana account 11111111111111111111111111111111.";
33 let mut chat_history = vec![Message::user(prompt)];
34
35 let result = loop {
36 let response = agent
37 .completion("", chat_history.clone())
38 .await
39 .unwrap()
40 .send()
41 .await
42 .unwrap();
43
44 let content = response.choice.first();
45
46 chat_history.push(Message::Assistant {
47 content: OneOrMany::one(content.clone()),
48 });
49
50 match content {
51 AssistantContent::Text(text) => {
52 break text;
53 }
54 AssistantContent::ToolCall(tool_call) => {
55 let tool_result = agent
56 .tools
57 .call(
58 &tool_call.function.name,
59 tool_call.function.arguments.to_string(),
60 )
61 .await
62 .unwrap();
63
64 chat_history.push(Message::User {
65 content: OneOrMany::one(UserContent::ToolResult(ToolResult {
66 id: tool_call.id,
67 content: OneOrMany::one(ToolResultContent::Text(Text {
68 text: tool_result,
69 })),
70 })),
71 })
72 }
73 }
74 };
75
76 println!("Assistant: {}", result.text);
77}