Expand description
Β§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 crate) to describe portable
language models, embeddings, moderation, image/audio generators, and more.
Every provider crate simply implements these traits.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β 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
β
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
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
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
β
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.
ModulesΒ§
- audio
- Audio generation and transcription.
- embedding
- Text embeddings.
- image
- Text-to-image generation.
- llm
- Language Models and Conversation Management
- moderation
- Content moderation utilities.
StructsΒ§
- Error
- The
Errortype, a wrapper around a dynamic error type.
TraitsΒ§
- Audio
Generator - Generates audio from text prompts.
- Audio
Transcriber - Transcribes audio to text.
- Embedding
Model - Converts text to vector representations.
- Image
Generator - Trait for generating and editing images from prompts and masks.
- Language
Model - Language models for text generation and conversation.
- Moderation
- Trait for content moderation services.
Type AliasesΒ§
- Result
- Result type used throughout the crate.
Attribute MacrosΒ§
- tool
- Converts an async function into an AI tool that can be called by language models.