pub struct OpenAiLanguageModel { /* private fields */ }Expand description
OpenAI Chat Completions API language model.
Calls POST {base_url}/chat/completions. Works with OpenAI directly or any OpenAI-compatible
endpoint via OpenAiConfig::base_url.
§Compatible Providers
| Provider | Base URL | Start command |
|---|---|---|
| OpenAI | https://api.openai.com/v1 (default) | — |
| MLX (text) | http://localhost:8080/v1 | mlx_lm.server --model <model> |
| MLX (vision) | http://localhost:8080/v1 | mlx_vlm.server --model <model> |
| vLLM | http://<host>/v1 | vllm serve <model> |
The Ollama daemon has its own provider impl (crate::OllamaLanguageModel) with
reasoning-effort defaults that differ from OpenAI’s.
Implementations§
Source§impl OpenAiLanguageModel
impl OpenAiLanguageModel
Sourcepub fn new(deps: OpenAiDeps, config: OpenAiConfig) -> Self
pub fn new(deps: OpenAiDeps, config: OpenAiConfig) -> Self
Create a new OpenAI language model.
Trait Implementations§
Source§impl LanguageModelProvider for OpenAiLanguageModel
impl LanguageModelProvider for OpenAiLanguageModel
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable provider key — used by the application router for
model_id.split_once('/') routing. Examples: "anthropic",
"openai", "ollama", "bedrock". Must be unique across the
providers registered for one modality.Source§fn capabilities(&self, model: &ModelId) -> Option<ModelCapabilities>
fn capabilities(&self, model: &ModelId) -> Option<ModelCapabilities>
Sync capability lookup against the provider’s static
MODEL_CAPABILITIES table. Returns None when the model is
not in the table (treat as conservative-deny for media content;
pure text calls bypass this lookup). Read moreSource§fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ChatModelInfo>, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ChatModelInfo>, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Catalog of models this provider serves. Read more
Source§fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: GenerateRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<LanguageModelResponse, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: GenerateRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<LanguageModelResponse, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a complete response.
Source§fn generate_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: GenerateRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LanguageModelError>> + Send>>, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: GenerateRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LanguageModelError>> + Send>>, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a streamed response — token deltas as a
Stream.Source§fn validate_request(
&self,
request: &GenerateRequest<'_>,
) -> Result<(), CapabilityError>
fn validate_request( &self, request: &GenerateRequest<'_>, ) -> Result<(), CapabilityError>
Validate that
request only carries content parts the model
actually accepts. Default impl walks request.messages, looks
up the model in the provider’s capability table, and returns
the first CapabilityError variant that applies — or Ok(())
for pure-text requests against text-only models. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for OpenAiLanguageModel
impl !UnwindSafe for OpenAiLanguageModel
impl Freeze for OpenAiLanguageModel
impl Send for OpenAiLanguageModel
impl Sync for OpenAiLanguageModel
impl Unpin for OpenAiLanguageModel
impl UnsafeUnpin for OpenAiLanguageModel
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.