ai-lib v0.3.4
Highlights:
- Provider Failover Support: v0.3.x introduced
AiClient::with_failover(Vec<Provider>). In 1.0+, compose the same behavior viaRoutingStrategyBuilder(see below). - Major Provider Expansion: Added 6 new AI providers including OpenRouter, Replicate, ZhipuAI, MiniMax, Perplexity, and AI21
- Enhanced Multimodal Content: Convenient
Content::from_image_file()andContent::from_audio_file()methods for automatic file processing - New Import System: Complete module tree restructuring with
preludefor better ergonomics and explicit top-level exports - Documentation Improvements: Comprehensive module tree guide and updated examples using latest library standards
New Features
Provider Failover / Strategy Builders
use ai_lib::prelude::*;
use ai_lib::provider::{RoutingStrategyBuilder, GroqBuilder, AnthropicBuilder, OpenAiBuilder};
let strategy = RoutingStrategyBuilder::new()
.with_provider(GroqBuilder::new().build_provider()?)
.with_provider(AnthropicBuilder::new().build_provider()?)
.build_failover()?;
let client = OpenAiBuilder::new()
.with_strategy(Box::new(strategy))
.build()?;
Multimodal Content Creation
use ai_lib::prelude::*;
// Image content from file
let image_content = Content::from_image_file("path/to/image.png");
// Audio content from file
let audio_content = Content::from_audio_file("path/to/audio.mp3");
// Mixed content message
let messages = vec![
Message {
role: Role::User,
content: Content::new_text("Analyze this image"),
function_call: None,
},
Message {
role: Role::User,
content: image_content,
function_call: None,
},
];
New Import Patterns
// Recommended for applications
use ai_lib::prelude::*;
// Explicit control
use ai_lib::{AiClient, Provider, Content, Message, Role};
New Providers
- OpenRouter (OpenAI-compatible): Unified gateway for multiple AI models
- Replicate (OpenAI-compatible): Access to various AI models
- ZhipuAI (OpenAI-compatible): GLM series models from China
- MiniMax (OpenAI-compatible): AI models from China
- Perplexity (Independent): Search-enhanced AI with custom API
- AI21 (Independent): Jurassic series models
Breaking Changes
- Moved
UsageandUsageStatus: Now intypes::responsemodule (deprecated aliases intypes::commonwill be removed before 1.0) provider::utilsmodule: Now internal (pub(crate)) - use publicContentmethods instead
Migration Guide
Usage and UsageStatus
// Old (deprecated)
use ai_lib::types::common::{Usage, UsageStatus};
// New (recommended)
use ai_lib::{Usage, UsageStatus};
// or
use ai_lib::types::response::{Usage, UsageStatus};
Provider Utils
// Old (no longer available)
use ai_lib::provider::utils::upload_file_with_transport;
// New (use Content methods)
let content = Content::from_image_file("path/to/image.png");
Upgrade
[dependencies]
ai-lib = "0.3.4"
Documentation
- Module Tree and Import Patterns - Complete guide to the new import system
- Application Import Patterns - Recommended patterns for different use cases
- API Reference - Complete API documentation
Compatibility
- Additive release: No breaking changes for existing code using public APIs
- Deprecation timeline: Deprecated items will be removed before 1.0
- Migration support: Comprehensive migration guide and examples provided