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
(azure, bedrock, groq, mistral,
deepseek, xai, openrouter,
together, fireworks, perplexity,
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 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 bedrock(region: &str, api_key: impl Into<String>) -> Self
pub fn bedrock(region: &str, api_key: impl Into<String>) -> Self
Amazon Bedrock, OpenAI-compatible endpoint with a Bedrock API key:
https://bedrock-runtime.{region}.amazonaws.com/openai/v1. Use Bedrock model IDs.
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 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.
Sourcepub fn with_max_retries(self, max_retries: u32) -> Self
pub fn with_max_retries(self, max_retries: u32) -> Self
How many times a failed request is retried (default DEFAULT_MAX_RETRIES; 0 disables).
Trait Implementations§
Source§impl Clone for OpenAiProvider
impl Clone for OpenAiProvider
Source§impl Debug for OpenAiProvider
impl Debug for OpenAiProvider
Source§impl EmbeddingProvider for OpenAiProvider
impl EmbeddingProvider for OpenAiProvider
fn embed<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
model: &'life1 str,
inputs: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = Result<Embeddings>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Source§impl LlmProvider for OpenAiProvider
impl LlmProvider for OpenAiProvider
Source§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,
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,
Source§fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
req: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
req: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
StreamEvent::Done
with the full response. Read more