pub struct OpenAiProvider { /* private fields */ }Expand description
OpenAI provider (GPT-4o, o1, embeddings).
Implementations§
Source§impl OpenAiProvider
impl OpenAiProvider
Sourcepub fn new(api_key: impl Into<String>) -> OpenAiProvider
pub fn new(api_key: impl Into<String>) -> OpenAiProvider
Construct with an explicit API key.
Sourcepub fn from_env() -> Result<OpenAiProvider, LlmError>
pub fn from_env() -> Result<OpenAiProvider, LlmError>
Construct from the OPENAI_API_KEY environment variable.
Sourcepub fn model(self, model: impl Into<String>) -> OpenAiProvider
pub fn model(self, model: impl Into<String>) -> OpenAiProvider
Set the default chat model.
Sourcepub fn embed_model(self, model: impl Into<String>) -> OpenAiProvider
pub fn embed_model(self, model: impl Into<String>) -> OpenAiProvider
Set the default embedding model.
Sourcepub fn base_url(self, base_url: impl Into<String>) -> OpenAiProvider
pub fn base_url(self, base_url: impl Into<String>) -> OpenAiProvider
Override the base URL (e.g. for an OpenAI-compatible gateway).
Sourcepub fn with_client(self, client: Client) -> OpenAiProvider
pub fn with_client(self, client: Client) -> OpenAiProvider
Provide a custom reqwest::Client (connection pooling, timeouts, …).
Trait Implementations§
Source§impl Clone for OpenAiProvider
impl Clone for OpenAiProvider
Source§fn clone(&self) -> OpenAiProvider
fn clone(&self) -> OpenAiProvider
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl LlmProvider for OpenAiProvider
impl LlmProvider for OpenAiProvider
Source§fn chat<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
Single-shot chat completion.
Source§fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LlmError>> + Send>>, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LlmError>> + Send>>, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
Streaming chat completion.
Source§fn embed<'life0, 'async_trait>(
&'life0 self,
req: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
fn embed<'life0, 'async_trait>(
&'life0 self,
req: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAiProvider: 'async_trait,
Generate embeddings.
Source§fn estimate_cost(&self, req: &ChatRequest) -> Option<CostEstimate>
fn estimate_cost(&self, req: &ChatRequest) -> Option<CostEstimate>
Pre-flight cost estimate (no network call).
None if unknown.Auto Trait Implementations§
impl !RefUnwindSafe for OpenAiProvider
impl !UnwindSafe for OpenAiProvider
impl Freeze for OpenAiProvider
impl Send for OpenAiProvider
impl Sync for OpenAiProvider
impl Unpin for OpenAiProvider
impl UnsafeUnpin for OpenAiProvider
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