1pub mod anthropic;
7pub mod factory;
8pub mod http;
9pub mod openai;
10pub mod structured;
11mod types;
12pub mod zhipu;
13
14pub use anthropic::AnthropicClient;
16pub use factory::{create_client_with_config, LlmConfig};
17pub use http::{
18 clear_http_metrics_callback, default_http_client, set_http_metrics_callback, HttpClient,
19 HttpMetricsCallback, HttpMetricsRecord, HttpResponse, StreamingHttpResponse,
20};
21pub use openai::OpenAiClient;
22pub use types::*;
23pub use zhipu::ZhipuClient;
24
25use anyhow::Result;
26use async_trait::async_trait;
27use tokio::sync::mpsc;
28use tokio_util::sync::CancellationToken;
29
30#[async_trait]
32pub trait LlmClient: Send + Sync {
33 async fn complete(
35 &self,
36 messages: &[Message],
37 system: Option<&str>,
38 tools: &[ToolDefinition],
39 ) -> Result<LlmResponse>;
40
41 async fn complete_streaming(
45 &self,
46 messages: &[Message],
47 system: Option<&str>,
48 tools: &[ToolDefinition],
49 cancel_token: CancellationToken,
50 ) -> Result<mpsc::Receiver<StreamEvent>>;
51
52 fn native_structured_support(&self) -> structured::NativeStructuredSupport {
57 structured::NativeStructuredSupport::None
58 }
59
60 async fn complete_structured(
67 &self,
68 messages: &[Message],
69 system: Option<&str>,
70 tools: &[ToolDefinition],
71 _directive: &structured::StructuredDirective,
72 ) -> Result<LlmResponse> {
73 self.complete(messages, system, tools).await
74 }
75
76 async fn complete_streaming_structured(
79 &self,
80 messages: &[Message],
81 system: Option<&str>,
82 tools: &[ToolDefinition],
83 _directive: &structured::StructuredDirective,
84 cancel_token: CancellationToken,
85 ) -> Result<mpsc::Receiver<StreamEvent>> {
86 self.complete_streaming(messages, system, tools, cancel_token)
87 .await
88 }
89}
90
91#[cfg(test)]
93#[path = "tests.rs"]
94mod tests_file;