pub struct OpenAiClient { /* private fields */ }Expand description
OpenAI Chat Completions API client.
Implements LlmClient against {base_url}/v1/chat/completions. Also
serves as the Groq client when base_url is set to
https://api.groq.com/openai — Groq exposes an OpenAI-compatible API.
§Authentication
Uses Authorization: Bearer {api_key} for all requests.
§Embeddings
embed() posts to {base_url}/v1/embeddings using model
text-embedding-3-small and extracts data[0].embedding as Vec<f32>.
Implementations§
Source§impl OpenAiClient
impl OpenAiClient
Sourcepub fn new(
api_key: String,
model: Option<String>,
base_url: Option<String>,
) -> Self
pub fn new( api_key: String, model: Option<String>, base_url: Option<String>, ) -> Self
Create a new client.
model: optional model override;Noneresolves todefault_model().base_url: optional base URL override;Nonedefaults tohttps://api.openai.com. PassSome("https://api.groq.com/openai")for Groq compatibility.
The internal reqwest::Client uses a 60-second timeout (T-165-04).
Trait Implementations§
Source§impl LlmClient for OpenAiClient
impl LlmClient for OpenAiClient
Source§fn default_model(&self) -> &str
fn default_model(&self) -> &str
The provider’s default model identifier. Read more
Source§fn complete<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run a non-streaming completion, returning the full response text.
Source§fn complete_stream<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<TokenStream, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete_stream<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<TokenStream, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run a streaming completion, returning a token stream. Read more
Source§fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a text embedding vector. Read more
Source§fn complete_with_tools<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete_with_tools<'life0, 'async_trait>(
&'life0 self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run a completion that may invoke tools. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAiClient
impl !UnwindSafe for OpenAiClient
impl Freeze for OpenAiClient
impl Send for OpenAiClient
impl Sync for OpenAiClient
impl Unpin for OpenAiClient
impl UnsafeUnpin for OpenAiClient
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