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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! # aither
//!
//! **Write AI applications that work with any provider** π
//!
//! This crate provides unified trait abstractions for AI models, letting you write code once
//! and switch between providers (`OpenAI`, `Anthropic`, local models, etc.) without changing your application logic.
//!
//!
//! ```text
//! βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
//! β Your App βββββΆβ aither ββββββ Providers β
//! β β β (this crate) β β β
//! β - Chat bots β β β β - openai β
//! β - Search β β - LanguageModel β β - anthropic β
//! β - Content gen β β - EmbeddingModel β β - llama.cpp β
//! β - Voice apps β β - ImageGenerator β β - whisper β
//! βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
//! ```
//!
//! ## Supported AI Capabilities
//!
//! | Capability | Trait | Description |
//! |------------|-------|-------------|
//! | **Language Models** | [`LanguageModel`] | Text generation, conversations, structured output |
//! | **Text Streaming** | [`TextStream`] | Unified interface for streaming text responses |
//! | **Embeddings** | [`EmbeddingModel`] | Convert text to vectors for semantic search |
//! | **Image Generation** | [`ImageGenerator`] | Create images with progressive quality improvement |
//! | **Text-to-Speech** | [`AudioGenerator`] | Generate speech audio from text |
//! | **Speech-to-Text** | [`AudioTranscriber`] | Transcribe audio to text |
//! | **Content Moderation** | [`Moderation`] | Detect policy violations with confidence scores |
//!
//! ## Examples
//!
//! ### Basic Chat Bot
//!
//! ```rust
//! use aither::{LanguageModel, llm::{Message, Request}};
//! use futures_lite::StreamExt;
//!
//! async fn chat_example(model: impl LanguageModel) -> aither::Result {
//! let messages = [
//! Message::system("You are a helpful assistant"),
//! Message::user("What's the capital of France?")
//! ];
//!
//! let request = Request::new(messages);
//! let mut response = model.respond(request);
//!
//! Ok(response.await?)
//! }
//! ```
//!
//! ### Structured Output with Tools
//!
//! ```rust
//! use aither::{LanguageModel, llm::{Message, Request, Tool}};
//! use serde::{Deserialize, Serialize};
//! use schemars::JsonSchema;
//!
//! #[derive(JsonSchema, Deserialize, Serialize)]
//! struct WeatherQuery {
//! location: String,
//! units: Option<String>,
//! }
//!
//! struct WeatherTool;
//!
//! impl Tool for WeatherTool {
//! const NAME: &str = "get_weather";
//! const DESCRIPTION: &str = "Get current weather for a location";
//! type Arguments = WeatherQuery;
//!
//! async fn call(&mut self, args: Self::Arguments) -> aither::Result {
//! Ok(format!("Weather in {}: 22Β°C, sunny", args.location))
//! }
//! }
//!
//! async fn weather_bot(model: impl LanguageModel) -> aither::Result {
//! let request = Request::new(vec![
//! Message::user("What's the weather like in Tokyo?")
//! ]).with_tool(WeatherTool);
//!
//! // Model can now call the weather tool automatically
//! let response: String = model.generate(request).await?;
//! Ok(response)
//! }
//! ```
//!
//! See [`llm::tool`] for more details on using tools with language models.
//!
//! ### Semantic Search with Embeddings
//!
//! ```rust
//! use aither::EmbeddingModel;
//!
//! async fn find_similar_docs(
//! model: impl EmbeddingModel,
//! query: &str,
//! documents: &[&str]
//! ) -> aither::Result<Vec<f32>> {
//! // Convert query to vector
//! let query_embedding = model.embed(query).await?;
//!
//! // In a real app, you'd compare with document embeddings
//! // and find the most similar ones using cosine similarity
//!
//! Ok(query_embedding)
//! }
//! ```
//!
//! ### Progressive Image Generation
//!
//! ```rust
//! use aither::{ImageGenerator, image::{Prompt, Size}};
//! use futures_lite::StreamExt;
//!
//! async fn generate_image(generator: impl ImageGenerator) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
//! let prompt = Prompt::new("A beautiful sunset over mountains");
//! let size = Size::square(1024);
//!
//! let mut image_stream = generator.create(prompt, size);
//! let mut final_image = Vec::new();
//!
//! // Each iteration gives us a complete image with progressively better quality
//! while let Some(image_result) = image_stream.next().await {
//! let current_image = image_result?;
//! final_image = current_image; // Keep the latest (highest quality) version
//!
//! // Optional: Display preview of current quality level
//! println!("Received image update, {} bytes", final_image.len());
//! }
//!
//! Ok(final_image) // Return the final highest-quality image
//! }
//! ```
//!
//!
extern crate alloc;
/// Audio generation and transcription.
///
/// Contains [`AudioGenerator`] and [`AudioTranscriber`] traits.
/// Text embeddings.
/// Text-to-image generation.
///
/// Contains [`ImageGenerator`] trait for creating images from text.
/// Content moderation utilities.
///
/// Contains traits and types for detecting and handling unsafe or inappropriate content.
use String;
pub use ;
pub use EmbeddingModel;
pub use ImageGenerator;
pub use LanguageModel;
pub use Moderation;
/// Result type used throughout the crate.
///
/// Type alias for [`anyhow::Result<T>`](anyhow::Result) with [`String`] as default success type.
pub type Result<T = String> = Result;
pub use Error;
// Re-export procedural macros
pub use cratetool;