pub mod anthropic;
pub mod factory;
pub mod http;
pub mod openai;
pub mod structured;
mod types;
pub mod zhipu;
pub use anthropic::AnthropicClient;
pub use factory::{create_client_with_config, LlmConfig};
pub use http::{
clear_http_metrics_callback, default_http_client, set_http_metrics_callback, HttpClient,
HttpMetricsCallback, HttpMetricsRecord, HttpResponse, StreamingHttpResponse,
};
pub use openai::OpenAiClient;
pub use types::*;
pub use zhipu::ZhipuClient;
use anyhow::Result;
use async_trait::async_trait;
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
#[async_trait]
pub trait LlmClient: Send + Sync {
async fn complete(
&self,
messages: &[Message],
system: Option<&str>,
tools: &[ToolDefinition],
) -> Result<LlmResponse>;
async fn complete_streaming(
&self,
messages: &[Message],
system: Option<&str>,
tools: &[ToolDefinition],
cancel_token: CancellationToken,
) -> Result<mpsc::Receiver<StreamEvent>>;
fn native_structured_support(&self) -> structured::NativeStructuredSupport {
structured::NativeStructuredSupport::None
}
async fn complete_structured(
&self,
messages: &[Message],
system: Option<&str>,
tools: &[ToolDefinition],
_directive: &structured::StructuredDirective,
) -> Result<LlmResponse> {
self.complete(messages, system, tools).await
}
async fn complete_streaming_structured(
&self,
messages: &[Message],
system: Option<&str>,
tools: &[ToolDefinition],
_directive: &structured::StructuredDirective,
cancel_token: CancellationToken,
) -> Result<mpsc::Receiver<StreamEvent>> {
self.complete_streaming(messages, system, tools, cancel_token)
.await
}
}
#[cfg(test)]
#[path = "tests.rs"]
mod tests_file;