Skip to main content

llm_kernel/llm/
mod.rs

1//! Async LLM client with OpenAI and Anthropic backends.
2//!
3//! The [`LLMClient`] trait provides a unified interface for chat completion
4//! and SSE streaming. Implementations: [`OpenAIClient`], [`AnthropicClient`].
5//!
6//! The [`json_extract`] module handles extracting structured JSON from
7//! raw LLM text output (code fences, raw JSON, etc.).
8//!
9//! Requires the `client-async` feature.
10
11/// Response cache wrapper for [`LLMClient`] over a [`KvStore`].
12///
13/// [`KvStore`]: crate::store::KvStore
14#[cfg(feature = "cache")]
15pub mod cache;
16/// Async LLM client implementations (OpenAI, Anthropic).
17#[cfg(feature = "client-async")]
18pub mod client;
19/// Conversation history with token-budget-aware truncation.
20#[cfg(feature = "tokens")]
21pub mod history;
22/// JSON extraction from raw LLM text output.
23pub mod json_extract;
24/// Middleware hooks for [`LLMClient`] request/response lifecycle.
25#[cfg(feature = "client-async")]
26pub mod middleware;
27/// Prompt template rendering.
28pub mod prompt;
29/// Exponential backoff retry wrapper for [`LLMClient`].
30#[cfg(feature = "client-async")]
31pub mod retry;
32/// Prompt templates with variable substitution and few-shot examples.
33pub mod template;
34/// Tool/function calling types.
35pub mod tool;
36/// Core LLM request/response types.
37pub mod types;
38
39#[cfg(feature = "cache")]
40pub use cache::CacheClient;
41#[cfg(feature = "client-async")]
42pub use client::{AnthropicClient, LLMClient, OpenAIClient};
43#[cfg(feature = "tokens")]
44pub use history::ConversationHistory;
45pub use json_extract::{JsonExtractor, extract_json, parse_json};
46#[cfg(feature = "client-async")]
47pub use middleware::{LLMClientMiddleware, MiddlewareClient, NoopMiddleware};
48pub use prompt::render_prompt;
49#[cfg(feature = "client-async")]
50pub use retry::{RetryClient, RetryConfig};
51pub use template::PromptTemplate;
52pub use tool::{ToolCall, ToolDefinition, ToolResult};
53#[cfg(feature = "client-async")]
54pub use types::LLMStream;
55pub use types::{
56    ChatMessage, ContentPart, LLMRequest, LLMRequestBuilder, LLMResponse, MessageRole, ModelConfig,
57    ResponseFormat, StreamEvent, TokenUsage,
58};