jsonplaceholder/
jsonplaceholder.rs1use rig::client::{CompletionClient, ProviderClient};
2use rig::completion::Prompt;
3use rig_openapi_tools::OpenApiToolset;
4
5#[tokio::main]
6async fn main() -> anyhow::Result<()> {
7 let openai = rig::providers::openai::Client::from_env();
8
9 let toolset = OpenApiToolset::from_file("examples/openapi.yaml")?;
10 println!("Loaded {} tools from OpenAPI spec", toolset.len());
11
12 let agent = openai
13 .agent("gpt-4o")
14 .preamble("You have access to API tools. Use them when asked.")
15 .tools(toolset.into_tools())
16 .build();
17
18 let response: String = agent
19 .prompt("Use the API tool to get user 1 and summarize the result.")
20 .await?;
21
22 println!("{response}");
23
24 Ok(())
25}