pub struct OpenAiProvider { /* private fields */ }Expand description
Client for the OpenAI Chat Completions API (POST {base_url}/chat/completions).
The same wire format is served by many other providers; use the presets
(groq, mistral, deepseek, xai,
openrouter, together, fireworks,
perplexity, azure, ollama,
lm_studio) or with_base_url for anything else (vLLM, LiteLLM, …).
Implementations§
Source§impl OpenAiProvider
impl OpenAiProvider
pub fn new(api_key: impl Into<String>) -> Self
Sourcepub fn openrouter(api_key: impl Into<String>) -> Self
pub fn openrouter(api_key: impl Into<String>) -> Self
OpenRouter: https://openrouter.ai/api/v1.
Sourcepub fn fireworks(api_key: impl Into<String>) -> Self
pub fn fireworks(api_key: impl Into<String>) -> Self
Fireworks AI: https://api.fireworks.ai/inference/v1.
Sourcepub fn perplexity(api_key: impl Into<String>) -> Self
pub fn perplexity(api_key: impl Into<String>) -> Self
Perplexity: https://api.perplexity.ai.
Sourcepub fn azure(resource: &str, api_key: impl Into<String>) -> Self
pub fn azure(resource: &str, api_key: impl Into<String>) -> Self
Azure OpenAI v1 API: https://{resource}.openai.azure.com/openai/v1, key in the api-key header.
Pass the deployment name as the model.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Points the client at another server. The key may be empty if the server does not need one.
Sourcepub fn with_client(self, client: Client) -> Self
pub fn with_client(self, client: Client) -> Self
Uses your own reqwest::Client, for example to share a connection pool or set a proxy.
Trait Implementations§
Source§impl Clone for OpenAiProvider
impl Clone for OpenAiProvider
Source§impl Debug for OpenAiProvider
impl Debug for OpenAiProvider
Source§impl LlmProvider for OpenAiProvider
impl LlmProvider for OpenAiProvider
fn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
req: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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