pub struct OpenAIClient { /* private fields */ }Expand description
Main OpenAI client that provides access to all APIs
Implementations§
Source§impl OpenAIClient
impl OpenAIClient
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self>
pub fn new(api_key: impl Into<String>) -> Result<Self>
Create a new OpenAI client with an API key
Sourcepub fn with_base_url(
api_key: impl Into<String>,
base_url: impl Into<String>,
) -> Result<Self>
pub fn with_base_url( api_key: impl Into<String>, base_url: impl Into<String>, ) -> Result<Self>
Create a new OpenAI client with custom base URL
Sourcepub async fn create_response(
&self,
request: &ResponseRequest,
) -> Result<ResponseResult>
pub async fn create_response( &self, request: &ResponseRequest, ) -> Result<ResponseResult>
Create a response using the responses API
Sourcepub async fn create_response_stream(
&self,
request: &ResponseRequest,
) -> Result<ResponseStream>
pub async fn create_response_stream( &self, request: &ResponseRequest, ) -> Result<ResponseStream>
Create a streaming response
Sourcepub async fn generate_text(
&self,
model: impl Into<String>,
prompt: impl Into<String>,
) -> Result<String>
pub async fn generate_text( &self, model: impl Into<String>, prompt: impl Into<String>, ) -> Result<String>
Generate text from a simple prompt
Sourcepub async fn generate_text_stream(
&self,
model: impl Into<String>,
prompt: impl Into<String>,
) -> Result<ResponseStream>
pub async fn generate_text_stream( &self, model: impl Into<String>, prompt: impl Into<String>, ) -> Result<ResponseStream>
Generate text with streaming
Sourcepub async fn generate_with_instructions(
&self,
model: impl Into<String>,
input: impl Into<String>,
instructions: impl Into<String>,
) -> Result<String>
pub async fn generate_with_instructions( &self, model: impl Into<String>, input: impl Into<String>, instructions: impl Into<String>, ) -> Result<String>
Generate text with instructions
Sourcepub async fn generate_with_instructions_stream(
&self,
model: impl Into<String>,
input: impl Into<String>,
instructions: impl Into<String>,
) -> Result<ResponseStream>
pub async fn generate_with_instructions_stream( &self, model: impl Into<String>, input: impl Into<String>, instructions: impl Into<String>, ) -> Result<ResponseStream>
Generate text with instructions and streaming
Sourcepub async fn create_chat_completion(
&self,
model: impl Into<String>,
messages: Vec<Message>,
) -> Result<String>
pub async fn create_chat_completion( &self, model: impl Into<String>, messages: Vec<Message>, ) -> Result<String>
Create a chat completion from messages
Sourcepub async fn create_chat_completion_stream(
&self,
model: impl Into<String>,
messages: Vec<Message>,
) -> Result<ResponseStream>
pub async fn create_chat_completion_stream( &self, model: impl Into<String>, messages: Vec<Message>, ) -> Result<ResponseStream>
Create a streaming chat completion
Sourcepub async fn chat(
&self,
model: impl Into<String>,
conversation: ChatBuilder,
) -> Result<String>
pub async fn chat( &self, model: impl Into<String>, conversation: ChatBuilder, ) -> Result<String>
Build a conversation and get response
Sourcepub async fn chat_stream(
&self,
model: impl Into<String>,
conversation: ChatBuilder,
) -> Result<ResponseStream>
pub async fn chat_stream( &self, model: impl Into<String>, conversation: ChatBuilder, ) -> Result<ResponseStream>
Build a conversation and get streaming response
Sourcepub async fn create_custom_response(
&self,
model: impl Into<String>,
input: ResponseInput,
temperature: Option<f32>,
max_tokens: Option<u32>,
instructions: Option<String>,
) -> Result<ResponseResult>
pub async fn create_custom_response( &self, model: impl Into<String>, input: ResponseInput, temperature: Option<f32>, max_tokens: Option<u32>, instructions: Option<String>, ) -> Result<ResponseResult>
Create a custom response with all parameters
Sourcepub fn responses(&self) -> &ResponsesApi
pub fn responses(&self) -> &ResponsesApi
Get access to the responses API
Sourcepub fn responses_v2(&self) -> &ResponsesApiV2
pub fn responses_v2(&self) -> &ResponsesApiV2
Get access to the modern Responses API
Sourcepub async fn create_response_v2(
&self,
request: &CreateResponseRequest,
) -> Result<ResponseObject>
pub async fn create_response_v2( &self, request: &CreateResponseRequest, ) -> Result<ResponseObject>
Create a response using the modern Responses API
Sourcepub async fn stream_response_v2(
&self,
request: &CreateResponseRequest,
) -> Result<ResponsesEventStream>
pub async fn stream_response_v2( &self, request: &CreateResponseRequest, ) -> Result<ResponsesEventStream>
Stream a response using the modern Responses API
Sourcepub async fn retrieve_response_v2(
&self,
response_id: &str,
) -> Result<ResponseObject>
pub async fn retrieve_response_v2( &self, response_id: &str, ) -> Result<ResponseObject>
Retrieve a response by ID using the modern Responses API
Sourcepub async fn delete_response_v2(
&self,
response_id: &str,
) -> Result<DeleteResponseAck>
pub async fn delete_response_v2( &self, response_id: &str, ) -> Result<DeleteResponseAck>
Delete a stored response using the modern Responses API
Sourcepub async fn cancel_response_v2(
&self,
response_id: &str,
) -> Result<ResponseObject>
pub async fn cancel_response_v2( &self, response_id: &str, ) -> Result<ResponseObject>
Cancel a background response request using the modern Responses API
Sourcepub async fn list_responses_v2(
&self,
params: &ResponsesListParams,
) -> Result<ResponseList>
pub async fn list_responses_v2( &self, params: &ResponsesListParams, ) -> Result<ResponseList>
List responses for the current project using the modern Responses API
Sourcepub async fn list_response_input_items_v2(
&self,
response_id: &str,
params: &StandardListParams,
) -> Result<ResponseInputItemList>
pub async fn list_response_input_items_v2( &self, response_id: &str, params: &StandardListParams, ) -> Result<ResponseInputItemList>
List input items for a particular response using the modern Responses API
Sourcepub fn streaming(&self) -> &StreamingApi
pub fn streaming(&self) -> &StreamingApi
Get access to the streaming API
Sourcepub fn functions(&self) -> &FunctionsApi
pub fn functions(&self) -> &FunctionsApi
Get access to the functions API
Sourcepub async fn create_function_response(
&self,
request: &ResponseRequest,
config: &FunctionConfig,
) -> Result<FunctionResponseResult>
pub async fn create_function_response( &self, request: &ResponseRequest, config: &FunctionConfig, ) -> Result<FunctionResponseResult>
Create a response with function calling support
Sourcepub async fn submit_function_results(
&self,
results: Vec<FunctionCallOutput>,
original_request: &ResponseRequest,
config: &FunctionConfig,
) -> Result<FunctionResponseResult>
pub async fn submit_function_results( &self, results: Vec<FunctionCallOutput>, original_request: &ResponseRequest, config: &FunctionConfig, ) -> Result<FunctionResponseResult>
Submit function call results and continue the conversation
Sourcepub async fn function_conversation(
&self,
model: impl Into<String> + Clone,
messages: Vec<Message>,
tools: Vec<Tool>,
max_iterations: Option<u32>,
) -> Result<Vec<FunctionResponseResult>>
pub async fn function_conversation( &self, model: impl Into<String> + Clone, messages: Vec<Message>, tools: Vec<Tool>, max_iterations: Option<u32>, ) -> Result<Vec<FunctionResponseResult>>
Execute a complete function calling conversation
Sourcepub async fn call_function(
&self,
model: impl Into<String>,
prompt: impl Into<String>,
tools: Vec<Tool>,
tool_choice: Option<ToolChoice>,
) -> Result<FunctionResponseResult>
pub async fn call_function( &self, model: impl Into<String>, prompt: impl Into<String>, tools: Vec<Tool>, tool_choice: Option<ToolChoice>, ) -> Result<FunctionResponseResult>
Create a simple function call
Sourcepub async fn chat_with_tools(
&self,
model: impl Into<String>,
conversation: ChatBuilder,
tools: Option<Vec<Tool>>,
tool_choice: Option<ToolChoice>,
) -> Result<FunctionResponseResult>
pub async fn chat_with_tools( &self, model: impl Into<String>, conversation: ChatBuilder, tools: Option<Vec<Tool>>, tool_choice: Option<ToolChoice>, ) -> Result<FunctionResponseResult>
Create a chat completion with optional tools
Sourcepub async fn execute_function_with_result(
&self,
call: &FunctionCall,
) -> Result<FunctionCallOutput>
pub async fn execute_function_with_result( &self, call: &FunctionCall, ) -> Result<FunctionCallOutput>
Execute a function call with automatic result handling
Trait Implementations§
Source§impl Clone for OpenAIClient
impl Clone for OpenAIClient
Source§fn clone(&self) -> OpenAIClient
fn clone(&self) -> OpenAIClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more