1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! MiniLLMLib - A minimalist Rust library for LLM interactions
//!
//! This library provides a clean, async-first interface for interacting with
//! Large Language Models via HTTP APIs (OpenRouter, OpenAI, etc.).
//!
//! # Features
//!
//! - **Conversation Trees**: `ChatNode` provides a tree-based conversation structure
//! supporting branching dialogues and conversation history
//! - **Streaming Support**: First-class support for streaming completions via SSE
//! - **Multimodal**: Support for images and audio in messages
//! - **Multiple wires**: One [`Provider`] trait owns the full dialect (endpoint,
//! auth, request body, response/stream envelope). Ships OpenAI/OpenRouter,
//! native Anthropic (`/v1/messages`, `content[]`), and a generic compatible
//! provider; a custom enterprise API is a small `impl Provider`.
//! - **Subscription auth**: a Claude Pro/Max OAuth token works via
//! [`Auth::BearerToken`] (see [`GeneratorInfo::claude_subscription`]); cost is a
//! token-count ESTIMATE through [`TokenPrice`].
//! - **Cost Tracking**: Per-provider usage & cost accounting behind the [`Provider`]
//! trait; enforced tracking via [`CompletionContext`], with honest
//! [`CostResolution`] (`Resolved`/`Unpriced`/`Unknown`, never a fake $0)
//! - **Cost Estimation**: What a call will cost BEFORE it is sent, so a caller can
//! decide whether to allow it. Off by default: enable the `estimate` feature.
//! See [Estimating a call's cost](#estimating-a-calls-cost).
//! - **JSON Repair**: Robust handling of malformed JSON from LLM outputs
//! - **Async/Parallel**: Built on Tokio for high-performance async operations
//!
//! # Quick Start
//!
//! ```no_run
//! use minillmlib::{ChatNode, GeneratorInfo};
//!
//! #[tokio::main]
//! async fn main() -> minillmlib::error::Result<()> {
//! // Create a generator for OpenRouter
//! let generator = GeneratorInfo::openrouter("anthropic/claude-3.5-sonnet");
//!
//! // Start a conversation
//! let root = ChatNode::root("You are a helpful assistant.");
//! let response = root.chat("Hello!", &generator).await?;
//!
//! println!("Assistant: {}", response.text().unwrap_or_default());
//! Ok(())
//! }
//! ```
//!
//! # Estimating a call's cost
//!
//! With the `estimate` feature, the generator answers directly (a deliberately
//! high figure, to reserve against):
//!
//! ```no_run
//! # #[cfg(feature = "estimate")]
//! # async fn example(generator: minillmlib::GeneratorInfo, prompt: minillmlib::ChatNode, params: minillmlib::CompletionParameters) -> minillmlib::error::Result<()> {
//! let usd = generator.estimate_cost_usd(&prompt.thread(), ¶ms).await?;
//! # Ok(())
//! # }
//! ```
//!
//! See [`GeneratorInfo::estimate_cost_usd`] and [`GeneratorInfo::model_rates`].
// Core modules
// Re-export main types for convenience
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Pre-call cost estimation. Requires the `estimate` feature, which pulls in a
/// BPE tokenizer that a plain completion has no use for.
pub use ;
pub use ;
pub use ;
pub use ;
/// Initialize the library with default settings
///
/// This loads environment variables from .env files and configures logging.
/// Initialize with a specific log level