pub struct ProviderFactory;Expand description
Provider 工厂:通过配置字符串自动实例化 LLM 客户端
支持三种配置方式:
- 模型名称:从配置文件/环境变量加载(如
"qwen3-max") - Provider:Model 格式:自动匹配内置 Provider(如
"anthropic:claude-sonnet-4-6"、"ollama:llama3") - 完整 LlmConfig:手动构造配置后调用
from_config()
§示例
use echo_integration::providers::ProviderFactory;
use echo_core::error::Result;
// 方式一:从配置文件加载
let client = ProviderFactory::create("qwen3-max")?;
// 方式二:Provider:Model 简写
let client = ProviderFactory::create("anthropic:claude-sonnet-4-6")?;
let client = ProviderFactory::create("ollama:llama3")?;
let client = ProviderFactory::create("deepseek:deepseek-chat")?;
// 方式三:从已有配置构建
use echo_integration::providers::LlmConfig;
let config = LlmConfig::anthropic("sk-ant-...", "claude-sonnet-4-6");
let client = ProviderFactory::from_config(&config)?;Implementations§
Source§impl ProviderFactory
impl ProviderFactory
Sourcepub fn create(config_str: &str) -> Result<Box<dyn LlmClient>, ReactError>
pub fn create(config_str: &str) -> Result<Box<dyn LlmClient>, ReactError>
通过配置字符串自动创建 LLM 客户端
解析规则:
- 含
:分隔符 → 解析为provider:model,自动填充 base_url,API key 从环境变量获取 - 不含
:→ 视为模型名称,从配置文件/环境变量加载完整配置
Sourcepub fn from_config(config: &LlmConfig) -> Result<Box<dyn LlmClient>, ReactError>
pub fn from_config(config: &LlmConfig) -> Result<Box<dyn LlmClient>, ReactError>
从 LlmConfig 构建客户端
Sourcepub fn supported_providers() -> &'static [&'static str]
pub fn supported_providers() -> &'static [&'static str]
列出所有支持的 provider 名称
Auto Trait Implementations§
impl Freeze for ProviderFactory
impl RefUnwindSafe for ProviderFactory
impl Send for ProviderFactory
impl Sync for ProviderFactory
impl Unpin for ProviderFactory
impl UnsafeUnpin for ProviderFactory
impl UnwindSafe for ProviderFactory
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> 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> 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 moreSource§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