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
187
188
189
190
191
192
193
194
195
196
197
198
//! # aither
//!
//! **Write AI applications that work with any provider** π
//!
//! `aither-core` hosts the no-std trait APIs that power the rest of the workspace. Use it directly
//! (or through the top-level [`aither`](https://crates.io/crates/aither) crate) to describe portable
//! language models, embeddings, moderation, image/audio generators, and more.
//! Every provider crate simply implements these traits.
//!
//!
//! ```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`] | Streaming events (text, reasoning, tool calls) |
//! | **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
//!
//! ### Streaming Responses with Events
//!
//! ```rust,ignore
//! use aither_core::llm::{LanguageModel, Event, Message, LLMRequest, model::Parameters};
//! use futures_lite::StreamExt;
//!
//! async fn event_demo(model: impl LanguageModel) -> aither_core::Result {
//! let request = LLMRequest::new([
//! Message::user("Explain how rainbows form like I'm five."),
//! ])
//! .with_parameters(Parameters::default().include_reasoning(true));
//!
//! let mut stream = model.respond(request);
//! let mut answer = String::new();
//!
//! while let Some(event) = stream.next().await {
//! match event? {
//! Event::Text(text) => answer.push_str(&text),
//! Event::Reasoning(thought) => println!("thinking: {}", thought),
//! Event::ToolCall(call) => println!("tool requested: {}", call.name),
//! _ => {}
//! }
//! }
//! Ok(answer)
//! }
//! ```
//!
//! ### Structured Output with Tools
//!
//! ```rust
//! use aither_core::llm::{LLMRequest, Message, Tool, ToolResult};
//! use schemars::JsonSchema;
//! use serde::Deserialize;
//! use std::borrow::Cow;
//!
//! /// Get current weather for a location.
//! #[derive(JsonSchema, Deserialize)]
//! struct WeatherQuery {
//! /// City to report on, e.g. "Tokyo".
//! location: String,
//! }
//!
//! struct WeatherTool;
//!
//! impl Tool for WeatherTool {
//! fn name(&self) -> Cow<'static, str> {
//! Cow::Borrowed("get_weather")
//! }
//!
//! type Arguments = WeatherQuery;
//! type Res = ToolResult;
//!
//! async fn call(&self, args: Self::Arguments) -> aither_core::Result<Self::Res> {
//! Ok(ToolResult::text(format!("Weather in {}: 22Β°C, sunny", args.location)))
//! }
//! }
//!
//! // Advertise the tool on a request. The model replies with a ToolCall event;
//! // executing it is up to the caller (see `aither-agent`).
//! let request = LLMRequest::new([Message::user("What is the weather in Tokyo?")])
//! .with_tool(&WeatherTool);
//! ```
//!
//! See [`llm::tool`] for more details on using tools with language models.
//!
//! ### Semantic Search with Embeddings
//!
//! ```rust
//! use aither_core::EmbeddingModel;
//!
//! async fn embed_query(
//! model: impl EmbeddingModel,
//! query: &str,
//! ) -> aither_core::Result<Vec<f32>> {
//! // Compare this against your stored document embeddings with cosine
//! // similarity, or hand it to `aither-rag`.
//! model.embed(query).await
//! }
//! ```
//!
//! ### Progressive Image Generation
//!
//! ```rust,ignore
//! use aither_core::{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
//! }
//! ```
//!
//! ## Modules
//!
//! - [`audio`] β text-to-speech and transcription traits.
//! - [`embedding`] β turn text into dense vectors.
//! - [`image`] β image generation + editing APIs.
//! - [`llm`] β request builders, messages, provider traits, reasoning streams.
//! - [`moderation`] β moderation scoring traits.
//!
//!
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;