pub struct OpenAITool {
pub tool_type: OpenAIToolType,
pub search_context_size: Option<String>,
pub user_location: Option<UserLocation>,
pub max_num_results: Option<u32>,
}Expand description
OpenAI server-side tool for the Responses API.
Supports web_search, file_search, and code_interpreter tools. Unlike GrokTool, each OpenAI tool has specific configuration options.
§Example
use openai_rust2::chat::OpenAITool;
// Web search with geographic filtering
let web_search = OpenAITool::web_search()
.with_search_context_size("high")
.with_user_location(UserLocation {
country: Some("US".to_string()),
city: Some("San Francisco".to_string()),
region: Some("CA".to_string()),
timezone: Some("America/Los_Angeles".to_string()),
});
// File search for document collections
let file_search = OpenAITool::file_search()
.with_max_num_results(10);
// Code interpreter for data analysis
let code_interpreter = OpenAITool::code_interpreter();Fields§
§tool_type: OpenAIToolTypeThe type of tool: “web_search”, “file_search”, or “code_interpreter”
search_context_size: Option<String>Controls the scope of information gathered for web_search: “high”, “medium”, or “low” Higher settings provide better answers but increase latency and cost. Only applies to web_search tool.
user_location: Option<UserLocation>Geographic location for filtering web search results. Only applies to web_search tool.
max_num_results: Option<u32>Maximum number of documents to return for file_search. Only applies to file_search tool.
Implementations§
Source§impl OpenAITool
impl OpenAITool
Sourcepub fn web_search() -> Self
pub fn web_search() -> Self
Create a web_search tool with default settings. Allows the model to search the web in real-time.
Sourcepub fn file_search() -> Self
pub fn file_search() -> Self
Create a file_search tool with default settings. Allows the model to search through uploaded files and documents.
Sourcepub fn code_interpreter() -> Self
pub fn code_interpreter() -> Self
Create a code_interpreter tool. Allows the model to execute Python code for calculations and analysis.
Sourcepub fn with_search_context_size(self, size: impl Into<String>) -> Self
pub fn with_search_context_size(self, size: impl Into<String>) -> Self
Set the search context size for web_search: “high”, “medium”, or “low”. Higher settings provide better answers but increase latency and cost.
Sourcepub fn with_user_location(self, location: UserLocation) -> Self
pub fn with_user_location(self, location: UserLocation) -> Self
Set geographic location for filtering web search results.
Sourcepub fn with_max_num_results(self, max_results: u32) -> Self
pub fn with_max_num_results(self, max_results: u32) -> Self
Set maximum number of documents to return for file_search.
Trait Implementations§
Source§impl Clone for OpenAITool
impl Clone for OpenAITool
Source§fn clone(&self) -> OpenAITool
fn clone(&self) -> OpenAITool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more