pub struct LlmClient { /* private fields */ }Expand description
LLM 客户端实现
Implementations§
Source§impl LlmClient
impl LlmClient
pub fn new(provider: LlmProvider, api_key: String) -> Self
Sourcepub fn with_base_url(self, base_url: String) -> Self
pub fn with_base_url(self, base_url: String) -> Self
创建客户端并指定自定义 base_url(覆盖 provider 默认值)
Sourcepub async fn send_stream_with_callback(
&self,
messages: Vec<Message>,
config: &LlmRequestConfig,
on_chunk: OnChunkCallback,
) -> Result<LlmResponse>
pub async fn send_stream_with_callback( &self, messages: Vec<Message>, config: &LlmRequestConfig, on_chunk: OnChunkCallback, ) -> Result<LlmResponse>
发送带回调的流式请求
Sourcepub async fn send_stream_abortable(
&self,
messages: Vec<Message>,
config: &LlmRequestConfig,
abort_flag: Arc<AtomicBool>,
) -> Result<LlmResponse>
pub async fn send_stream_abortable( &self, messages: Vec<Message>, config: &LlmRequestConfig, abort_flag: Arc<AtomicBool>, ) -> Result<LlmResponse>
发送可中断的流式请求
Sourcepub async fn send_with_retry(
&self,
messages: Vec<Message>,
config: &LlmRequestConfig,
max_retries: u32,
) -> Result<LlmResponse>
pub async fn send_with_retry( &self, messages: Vec<Message>, config: &LlmRequestConfig, max_retries: u32, ) -> Result<LlmResponse>
带错误恢复的请求重试
Sourcepub async fn send_stream_with_retry(
&self,
messages: Vec<Message>,
config: &LlmRequestConfig,
max_retries: u32,
) -> Result<LlmResponse>
pub async fn send_stream_with_retry( &self, messages: Vec<Message>, config: &LlmRequestConfig, max_retries: u32, ) -> Result<LlmResponse>
带错误恢复的流式请求重试
Source§impl LlmClient
impl LlmClient
Sourcepub fn build_anthropic_messages_url(base_url: &str) -> String
pub fn build_anthropic_messages_url(base_url: &str) -> String
Construct the messages endpoint URL for Anthropic API
Handles three cases:
- Official Anthropic API: https://api.anthropic.com -> https://api.anthropic.com/v1/messages
- Already contains full path: https://api.example.com/anthropic/messages -> unchanged
- Anthropic-compatible endpoint (contains /anthropic): https://api.example.com/anthropic -> /messages
- Already contains v1: https://api.example.com/v1 -> https://api.example.com/v1/messages
Trait Implementations§
Source§impl LlmClientTrait for LlmClient
impl LlmClientTrait for LlmClient
Source§fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: &'life1 LlmRequestConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: &'life1 LlmRequestConfig,
) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
发送请求并获取响应
Source§fn send_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: &'life1 LlmRequestConfig,
) -> Pin<Box<dyn Future<Output = Result<MessageStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
config: &'life1 LlmRequestConfig,
) -> Pin<Box<dyn Future<Output = Result<MessageStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
发送请求并流式获取响应
Auto Trait Implementations§
impl !RefUnwindSafe for LlmClient
impl !UnwindSafe for LlmClient
impl Freeze 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