pub struct LLMClient { /* private fields */ }Expand description
LLM Client unified entry point
Wraps any BaseChatModel as Arc<dyn BaseChatModel<Error = ProviderError>>,
providing zero-config auto-detection and explicit construction.
Implements Deref<Target = dyn BaseChatModel>, so you can call .chat() etc. directly.
Implementations§
Source§impl LLMClient
impl LLMClient
Sourcepub fn from_env() -> Result<Self, ProviderError>
pub fn from_env() -> Result<Self, ProviderError>
Create LLM Client from environment variables (auto-detect)
Detection priority:
OPENAI_API_KEY-> OpenAIChatANTHROPIC_API_KEY-> AnthropicChatAZURE_OPENAI_API_KEY-> AzureOpenAIChatDEEPSEEK_API_KEY-> DeepSeekChatQWEN_API_KEY-> QwenChatMOONSHOT_API_KEY-> MoonshotChatZHIPU_API_KEY-> ZhipuChatMISTRAL_API_KEY-> MistralChatCOHERE_API_KEY-> CohereChatGEMINI_API_KEY(orGOOGLE_API_KEY) -> GeminiChatOLLAMA_BASE_URL-> OllamaChat
§Errors
Returns error if no known environment variable is set.
Sourcepub fn openai(config: OpenAIConfig) -> Self
pub fn openai(config: OpenAIConfig) -> Self
Create OpenAI Client
Sourcepub fn anthropic(config: AnthropicConfig) -> Self
pub fn anthropic(config: AnthropicConfig) -> Self
Create Anthropic Client
Sourcepub fn ollama(config: OllamaConfig) -> Self
pub fn ollama(config: OllamaConfig) -> Self
Create Ollama Client
Sourcepub fn gemini(config: GeminiConfig) -> Self
pub fn gemini(config: GeminiConfig) -> Self
Create Gemini Client
Sourcepub fn deepseek(config: DeepSeekConfig) -> Self
pub fn deepseek(config: DeepSeekConfig) -> Self
Create DeepSeek Client
Sourcepub fn qwen(config: QwenConfig) -> Self
pub fn qwen(config: QwenConfig) -> Self
Create Qwen Client
Sourcepub fn moonshot(config: MoonshotConfig) -> Self
pub fn moonshot(config: MoonshotConfig) -> Self
Create Moonshot Client
Sourcepub fn zhipu(config: ZhipuConfig) -> Self
pub fn zhipu(config: ZhipuConfig) -> Self
Create Zhipu Client
Sourcepub fn mistral(config: MistralConfig) -> Self
pub fn mistral(config: MistralConfig) -> Self
Create Mistral Client
Sourcepub fn azure(config: AzureOpenAIConfig) -> Self
pub fn azure(config: AzureOpenAIConfig) -> Self
Create Azure OpenAI Client
Sourcepub fn cohere(config: CohereConfig) -> Self
pub fn cohere(config: CohereConfig) -> Self
Create Cohere Client
Sourcepub fn from_arc(
llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>,
) -> Self
pub fn from_arc( llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>, ) -> Self
Create Client from Arc<dyn BaseChatModel>
Sourcepub fn into_inner(
self,
) -> Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync> ⓘ
pub fn into_inner( self, ) -> Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync> ⓘ
Get the inner Arc<dyn BaseChatModel>, can be passed directly to Agent
Sourcepub fn inner(
&self,
) -> &Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync> ⓘ
pub fn inner( &self, ) -> &Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync> ⓘ
Get inner reference
Trait Implementations§
Source§impl BaseChatModel for LLMClient
impl BaseChatModel for LLMClient
Source§fn chat<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<LLMResult, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<LLMResult, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Chat with the model. Read more
Source§fn stream_chat<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_chat<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream chat with the model. Read more
Source§fn bind_tools(
&self,
tools: Vec<ToolDefinition>,
) -> Option<Box<dyn BaseChatModel<Error = ProviderError> + Send + Sync>>
fn bind_tools( &self, tools: Vec<ToolDefinition>, ) -> Option<Box<dyn BaseChatModel<Error = ProviderError> + Send + Sync>>
Bind tool definitions for function calling. Read more
Source§impl BaseLanguageModel<Vec<Message>, LLMResult> for LLMClient
impl BaseLanguageModel<Vec<Message>, LLMResult> for LLMClient
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Returns the model name.
Source§fn temperature(&self) -> Option<f32>
fn temperature(&self) -> Option<f32>
Returns the temperature parameter.
Source§fn max_tokens(&self) -> Option<usize>
fn max_tokens(&self) -> Option<usize>
Returns the max tokens limit.
Source§fn with_temperature(self, temp: f32) -> Selfwhere
Self: Sized,
fn with_temperature(self, temp: f32) -> Selfwhere
Self: Sized,
Sets the temperature parameter.
Source§fn with_max_tokens(self, max: usize) -> Selfwhere
Self: Sized,
fn with_max_tokens(self, max: usize) -> Selfwhere
Self: Sized,
Sets the max tokens limit.
Source§impl Runnable<Vec<Message>, LLMResult> for LLMClient
impl Runnable<Vec<Message>, LLMResult> for LLMClient
Source§type Error = ProviderError
type Error = ProviderError
Error type.
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<LLMResult, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<LLMResult, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Transforms single input to output. Read more
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Vec<Message>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<LLMResult>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Vec<Message>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<LLMResult>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch processing - transforms multiple inputs to outputs. Read more
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LLMResult, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LLMResult, ProviderError>> + Send>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Streaming output - for real-time responses (LLM, etc). Read more
Source§fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Batch processing that returns results in completion order. Read more
Source§fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send + 'life0>>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send + 'life0>>, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Stream-to-stream transformation - the core of LCEL streaming. Read more
Auto Trait Implementations§
impl !Freeze for LLMClient
impl !RefUnwindSafe for LLMClient
impl !UnwindSafe for LLMClient
impl Send for LLMClient
impl Sync for LLMClient
impl Unpin for LLMClient
impl UnsafeUnpin for LLMClient
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<I, O, R> RunnableExt<I, O> for R
impl<I, O, R> RunnableExt<I, O> for R
Source§fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
Pipe the output of this runnable into another runnable. Read more
Source§fn into_sequence(self) -> RunnableSequence<Input, Output>
fn into_sequence(self) -> RunnableSequence<Input, Output>
Create a
RunnableSequence from this runnable as a single step. Read moreSource§fn with_fallbacks<R>(
self,
fallbacks: Vec<R>,
) -> RunnableWithFallbacks<Input, Output>
fn with_fallbacks<R>( self, fallbacks: Vec<R>, ) -> RunnableWithFallbacks<Input, Output>
Add fallback runnables that are tried if this one fails. Read more
Source§fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
Wrap this runnable with retry logic using exponential backoff. Read more
Source§fn configurable_alternatives<K, R>(
self,
which: impl Into<String>,
default_key: impl Into<String>,
alternatives: Vec<(K, R)>,
) -> RunnableConfigurable<Input, Output>
fn configurable_alternatives<K, R>( self, which: impl Into<String>, default_key: impl Into<String>, alternatives: Vec<(K, R)>, ) -> RunnableConfigurable<Input, Output>
Route between a default runnable and named alternatives at invoke time. Read more
Source§fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
Override recognized config fields at invoke time from
config.configurable (Python’s Runnable.configurable_fields). Read moreSource§impl<M> StreamingStructuredOutputExt for Mwhere
M: BaseChatModel,
impl<M> StreamingStructuredOutputExt for Mwhere
M: BaseChatModel,
Source§fn stream_structured_output<'life0, 'life1, 'async_trait, T>(
&'life0 self,
schema: Value,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<T, StructuredOutputError>> + Send>>, StructuredOutputError>> + Send + 'async_trait>>
fn stream_structured_output<'life0, 'life1, 'async_trait, T>( &'life0 self, schema: Value, prompt: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<T, StructuredOutputError>> + Send>>, StructuredOutputError>> + Send + 'async_trait>>
Stream structured output from a chat model. Read more
Source§impl<M> StructuredOutputExt for Mwhere
M: BaseChatModel,
impl<M> StructuredOutputExt for Mwhere
M: BaseChatModel,
Source§fn with_structured_output<'life0, 'life1, 'async_trait, T>(
&'life0 self,
schema: Value,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<T, StructuredOutputError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + DeserializeOwned + Serialize + Send + Sync + 'static,
Self: Sync + 'async_trait,
fn with_structured_output<'life0, 'life1, 'async_trait, T>(
&'life0 self,
schema: Value,
prompt: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<T, StructuredOutputError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + DeserializeOwned + Serialize + Send + Sync + 'static,
Self: Sync + 'async_trait,
Call the LLM with a JSON schema and prompt, returning a parsed result of type
T. Read more