vectorless/llm/mod.rs
1// Copyright (c) 2026 vectorless developers
2// SPDX-License-Identifier: Apache-2.0
3
4//! Unified LLM client module.
5//!
6//! This module provides a unified interface for all LLM operations across the codebase:
7//! - **Summarization** — Generating document summaries
8//! - **Retrieval** — Document tree navigation
9//! - **TOC Processing** — Table of contents extraction
10//!
11//! # Features
12//!
13//! - Unified configuration with purpose-specific presets
14//! - Automatic retry with exponential backoff
15//! - JSON response parsing
16//! - Unified error handling
17//!
18//! # Architecture
19//!
20//! ```text
21//! ┌─────────────────────────────────────────────────────────────────┐
22//! │ LlmPool │
23//! │ │
24//! │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
25//! │ │ summary │ │ retrieval │ │ toc │ │
26//! │ │ LlmClient │ │ LlmClient │ │ LlmClient │ │
27//! │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
28//! │ │ │ │ │
29//! │ └────────────────┼────────────────┘ │
30//! │ │ │
31//! │ ▼ │
32//! │ ┌─────────────────────┐ │
33//! │ │ async-openai │ │
34//! │ └─────────────────────┘ │
35//! └─────────────────────────────────────────────────────────────────┘
36//! ```
37//!
38//! # Example
39//!
40//! ```rust,no_run
41//! use vectorless::llm::{LlmPool, LlmConfig, RetryConfig};
42//!
43//! # #[tokio::main]
44//! # async fn main() -> vectorless::llm::LlmResult<()> {
45//! // Create a pool with default configurations
46//! let pool = LlmPool::from_defaults();
47//!
48//! // Use summary client
49//! let summary = pool.summary().complete(
50//! "You summarize text concisely.",
51//! "Long text to summarize..."
52//! ).await?;
53//!
54//! // Use retrieval client with JSON output
55//! #[derive(serde::Deserialize)]
56//! struct NavDecision { section: usize }
57//! let decision: NavDecision = pool.retrieval().complete_json(
58//! "You navigate documents.",
59//! "Find section about X..."
60//! ).await?;
61//!
62//! # Ok(())
63//! # }
64//! ```
65
66mod client;
67mod config;
68mod error;
69mod fallback;
70mod pool;
71mod retry;
72
73pub use client::LlmClient;
74pub use config::{LlmConfig, LlmConfigs, RetryConfig};
75pub use error::{LlmError, LlmResult};
76pub use fallback::{FallbackChain, FallbackConfig, FallbackResult, FallbackStep};
77pub use pool::LlmPool;