Expand description
§Aidale
Elegant Rust AI SDK inspired by OpenDAL’s architecture.
Aidale provides a unified, composable interface for interacting with multiple AI providers (OpenAI, Anthropic, etc.) with support for middleware layers and extensible plugins.
§Features
- Zero-cost abstractions: Static dispatch during building, single type erasure at runtime
- Composable layers: Stack multiple layers (logging, retry, caching, etc.)
- Plugin system: Extend runtime behavior with hooks
- Type safety: Leverage Rust’s type system for correctness
- Async/await: Full async support with tokio
§Quick Start
[dependencies]
aidale = { version = "0.1", features = ["openai", "layers"] }ⓘ
use aidale::{RuntimeExecutor, Message, TextParams};
use aidale::provider::OpenAiProvider;
use aidale::layer::LoggingLayer;
// Create provider
let provider = OpenAiProvider::builder()
.api_key("your-api-key")
.build()?;
// Build executor with layers
let executor = RuntimeExecutor::builder(provider)
.layer(LoggingLayer::new())
.finish();
// Generate text
let params = TextParams::new(vec![
Message::user("What is Rust?"),
]);
let result = executor.generate_text("gpt-3.5-turbo", params).await?;
println!("{}", result.content);§Feature Flags
default: Includesopenaiprovideropenai: OpenAI provider supportproviders: All available providerslayers: Built-in layers (logging, retry, caching, etc.)plugins: Built-in plugins (tool use, etc.)full: All features enabled
Modules§
- error
- Error types for AI Core operations.
- layer
- Built-in middleware layers.
- plugin
- Built-in runtime plugins.
- prelude
- Prelude module for convenient imports Prelude module containing the most commonly used types and traits.
- provider
- AI provider implementations.
- runtime
- Runtime layer for AI Core.
- strategy
- Strategy layer for provider-specific behaviors.
- types
- Core types for AI operations.
Macros§
- impl_
layered_ provider - Macro to implement Provider trait by forwarding to LayeredProvider methods.
Structs§
- Chat
Completion Chunk - Chat completion streaming chunk
- Chat
Completion Request - Chat completion request
- Chat
Completion Response - Chat completion response
- Choice
- Single choice in chat completion response
- Choice
Delta - Delta choice in streaming response
- Json
Mode Strategy - JSON Mode strategy for providers that only support basic JSON object mode.
- Json
Schema Strategy - JSON Schema strategy for providers that support strict JSON Schema.
- Message
- Message in a conversation
- Message
Delta - Message delta for streaming
- Object
Params - Object generation parameters
- Object
Request - Object request
- Object
Response - Object response
- Object
Result - Object generation result
- Plugin
Engine - Plugin execution engine.
- Provider
Info - Provider information
- Request
Context - Request context for plugins
- Runtime
Executor - Runtime executor with plugin support.
- Text
Chunk - Streaming text chunk
- Text
Params - Text generation parameters
- Text
Request - Text request with provider info
- Text
Response - Response metadata from streaming
- Text
Result - Text generation result
- Tool
- Tool definition
- Usage
- Usage statistics
Enums§
- AiError
- The main error type for AI operations.
- Content
Part - Message content part
- Finish
Reason - Finish reason
- Plugin
Phase - Plugin execution phase
- Response
Format - Response format for chat completions
- Role
- Message role
Traits§
- Json
Output Strategy - Strategy for handling JSON output in chat completion requests.
- Layer
- Layer trait for wrapping providers.
- Layered
Provider - Helper trait for layered providers.
- Plugin
- Plugin trait for runtime-level hooks.
- Provider
- Core provider trait for AI services.
Type Aliases§
- Result
- Result type alias for AI operations