pub struct ProviderBuilder<P: Protocol> { /* private fields */ }Expand description
Provider 构建器
提供链式调用的 API 来构建 Provider,统一处理所有配置项。
§示例
use llm_connector::core::{ProviderBuilder, Protocol};
use llm_connector::protocols::OpenAIProtocol;
let provider = ProviderBuilder::new(
OpenAIProtocol::new("sk-..."),
"https://api.openai.com"
)
.timeout(60)
.proxy("http://proxy:8080")
.header("X-Custom-Header", "value")
.build()
.unwrap();Implementations§
Source§impl<P: Protocol> ProviderBuilder<P>
impl<P: Protocol> ProviderBuilder<P>
Sourcepub fn timeout(self, secs: u64) -> Self
pub fn timeout(self, secs: u64) -> Self
设置超时时间(秒)
§示例
let builder = ProviderBuilder::new(
OpenAIProtocol::new("sk-..."),
"https://api.openai.com"
)
.timeout(60); // 60秒超时Sourcepub fn proxy(self, proxy: &str) -> Self
pub fn proxy(self, proxy: &str) -> Self
设置代理
§示例
let builder = ProviderBuilder::new(
OpenAIProtocol::new("sk-..."),
"https://api.openai.com"
)
.proxy("http://proxy:8080");Sourcepub fn header(self, key: &str, value: &str) -> Self
pub fn header(self, key: &str, value: &str) -> Self
添加额外的 HTTP 头部
注意:这些头部会与协议的认证头部合并。
§示例
let builder = ProviderBuilder::new(
OpenAIProtocol::new("sk-..."),
"https://api.openai.com"
)
.header("X-Custom-Header", "value")
.header("X-Another-Header", "value2");Sourcepub fn build(self) -> Result<GenericProvider<P>, LlmConnectorError>
pub fn build(self) -> Result<GenericProvider<P>, LlmConnectorError>
Auto Trait Implementations§
impl<P> Freeze for ProviderBuilder<P>where
P: Freeze,
impl<P> RefUnwindSafe for ProviderBuilder<P>where
P: RefUnwindSafe,
impl<P> Send for ProviderBuilder<P>
impl<P> Sync for ProviderBuilder<P>
impl<P> Unpin for ProviderBuilder<P>where
P: Unpin,
impl<P> UnwindSafe for ProviderBuilder<P>where
P: UnwindSafe,
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