pub struct OpenApiToolsetBuilder { /* private fields */ }Expand description
Builder for configuring an OpenApiToolset.
Implementations§
Source§impl OpenApiToolsetBuilder
impl OpenApiToolsetBuilder
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
pub fn base_url(self, url: impl Into<String>) -> Self
Override the base URL from the spec.
Examples found in repository?
examples/petstore.rs (line 13)
8async fn main() -> anyhow::Result<()> {
9 let openai = rig::providers::openai::Client::from_env();
10
11 // Parse once at startup — reuse across requests
12 let toolset = OpenApiToolset::builder_from_file("examples/petstore.json")?
13 .base_url("https://petstore3.swagger.io/api/v3")
14 .build()?;
15
16 println!("Loaded {} tools from Petstore spec\n", toolset.len());
17
18 // Simulate a per-request context (e.g. from a logged-in user session)
19 let visible_ctx = HashMap::from([
20 ("username".to_string(), "user1".to_string()),
21 ("preferred_status".to_string(), "available".to_string()),
22 ]);
23 let context_preamble = OpenApiToolset::context_preamble(&visible_ctx);
24
25 let preamble = format!(
26 "You have access to the Swagger Petstore API. \
27 Use the available tools to answer questions about the pet store.\n\n\
28 {context_preamble}"
29 );
30
31 // Create agent with per-request tools (cheap clone)
32 let agent = openai
33 .agent("gpt-4o")
34 .preamble(&preamble)
35 .tools(toolset.tools_with_context(&HashMap::new()))
36 .build();
37
38 let prompts = [
39 "What pets are currently available in the store? Show me the first 3.",
40 "Get the store inventory and tell me the status counts.",
41 "Look up my user profile and summarize it.",
42 ];
43
44 for prompt in prompts {
45 println!(">>> {prompt}");
46 let response: String = agent.prompt(prompt).await?;
47 println!("{response}\n");
48 }
49
50 Ok(())
51}Sourcepub fn client(self, client: Client) -> Self
pub fn client(self, client: Client) -> Self
Provide a pre-configured reqwest client (e.g. with default auth headers or timeouts).
Add a hidden context parameter that will be auto-injected into tool calls. The LLM will not see this parameter in the tool schema.
Sourcepub fn bearer_token(self, token: &str) -> Self
pub fn bearer_token(self, token: &str) -> Self
Convenience: create a client with a bearer token Authorization header.
Sourcepub fn build(self) -> Result<OpenApiToolset>
pub fn build(self) -> Result<OpenApiToolset>
Build the toolset, parsing the spec and creating tools.
Examples found in repository?
examples/petstore.rs (line 14)
8async fn main() -> anyhow::Result<()> {
9 let openai = rig::providers::openai::Client::from_env();
10
11 // Parse once at startup — reuse across requests
12 let toolset = OpenApiToolset::builder_from_file("examples/petstore.json")?
13 .base_url("https://petstore3.swagger.io/api/v3")
14 .build()?;
15
16 println!("Loaded {} tools from Petstore spec\n", toolset.len());
17
18 // Simulate a per-request context (e.g. from a logged-in user session)
19 let visible_ctx = HashMap::from([
20 ("username".to_string(), "user1".to_string()),
21 ("preferred_status".to_string(), "available".to_string()),
22 ]);
23 let context_preamble = OpenApiToolset::context_preamble(&visible_ctx);
24
25 let preamble = format!(
26 "You have access to the Swagger Petstore API. \
27 Use the available tools to answer questions about the pet store.\n\n\
28 {context_preamble}"
29 );
30
31 // Create agent with per-request tools (cheap clone)
32 let agent = openai
33 .agent("gpt-4o")
34 .preamble(&preamble)
35 .tools(toolset.tools_with_context(&HashMap::new()))
36 .build();
37
38 let prompts = [
39 "What pets are currently available in the store? Show me the first 3.",
40 "Get the store inventory and tell me the status counts.",
41 "Look up my user profile and summarize it.",
42 ];
43
44 for prompt in prompts {
45 println!(">>> {prompt}");
46 let response: String = agent.prompt(prompt).await?;
47 println!("{response}\n");
48 }
49
50 Ok(())
51}Auto Trait Implementations§
impl Freeze for OpenApiToolsetBuilder
impl !RefUnwindSafe for OpenApiToolsetBuilder
impl Send for OpenApiToolsetBuilder
impl Sync for OpenApiToolsetBuilder
impl Unpin for OpenApiToolsetBuilder
impl UnsafeUnpin for OpenApiToolsetBuilder
impl !UnwindSafe for OpenApiToolsetBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more