pub struct OpenAIProtocolLlmDriver { /* private fields */ }Expand description
OpenAI Protocol LLM Driver
Base implementation of LlmDriver for OpenAI-compatible APIs.
Supports streaming responses and tool calls.
Rate limit handling: On 429 errors, automatically retries with exponential
backoff, respecting x-ratelimit-reset-* and retry-after headers.
This is the base protocol driver used in examples and for OpenAI-compatible endpoints.
For production use with OpenAI, consider using OpenAILlmDriver from the everruns-openai crate.
§Example
ⓘ
use everruns_core::OpenAIProtocolLlmDriver;
let driver = OpenAIProtocolLlmDriver::from_env()?;
// or
let driver = OpenAIProtocolLlmDriver::new("your-api-key");
// or with custom endpoint
let driver = OpenAIProtocolLlmDriver::with_base_url("your-api-key", "https://api.example.com/v1/chat/completions");
// or with custom retry config
let driver = OpenAIProtocolLlmDriver::new("your-api-key")
.with_retry_config(LlmRetryConfig::aggressive());Implementations§
Source§impl OpenAIProtocolLlmDriver
impl OpenAIProtocolLlmDriver
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new driver from the OPENAI_API_KEY environment variable
Sourcepub fn with_base_url(
api_key: impl Into<String>,
api_url: impl Into<String>,
) -> Self
pub fn with_base_url( api_key: impl Into<String>, api_url: impl Into<String>, ) -> Self
Create a new driver with a custom API URL (for OpenAI-compatible APIs)
Sourcepub fn with_retry_config(self, config: LlmRetryConfig) -> Self
pub fn with_retry_config(self, config: LlmRetryConfig) -> Self
Configure retry behavior for rate limit errors
Trait Implementations§
Source§impl Clone for OpenAIProtocolLlmDriver
impl Clone for OpenAIProtocolLlmDriver
Source§fn clone(&self) -> OpenAIProtocolLlmDriver
fn clone(&self) -> OpenAIProtocolLlmDriver
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 Debug for OpenAIProtocolLlmDriver
impl Debug for OpenAIProtocolLlmDriver
Source§impl LlmDriver for OpenAIProtocolLlmDriver
impl LlmDriver for OpenAIProtocolLlmDriver
Source§fn chat_completion_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<LlmMessage>,
config: &'life1 LlmCallConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponseStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_completion_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<LlmMessage>,
config: &'life1 LlmCallConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponseStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Call the LLM with streaming response
Source§fn chat_completion<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<LlmMessage>,
config: &'life1 LlmCallConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_completion<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<LlmMessage>,
config: &'life1 LlmCallConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Call the LLM without streaming (convenience method)
Source§fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<DiscoveredModel>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<DiscoveredModel>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List available models from the provider Read more
Source§fn supports_compact(&self) -> bool
fn supports_compact(&self) -> bool
Check if this driver supports the compact endpoint Read more
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAIProtocolLlmDriver
impl !UnwindSafe for OpenAIProtocolLlmDriver
impl Freeze for OpenAIProtocolLlmDriver
impl Send for OpenAIProtocolLlmDriver
impl Sync for OpenAIProtocolLlmDriver
impl Unpin for OpenAIProtocolLlmDriver
impl UnsafeUnpin for OpenAIProtocolLlmDriver
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request