Expand description
rustlavel-ai: one API for talking to language models.
Laravel 13 shipped an AI SDK as a first-party package; this is the same idea
in Rust. Anthropic, OpenAI and Ollama sit behind one Provider trait, so
the difference between them is a line of configuration rather than a
rewrite, and Ai::fake() means an application’s tests need neither a key
nor a network.
The common case is one line:
let answer = Ai::from_config(&config)?.prompt("Summarise this article").text().await?;and so is streaming it:
let mut stream = ai.prompt("Tell me a story").stream().await?;
while let Some(delta) = stream.next().await? {
print!("{delta}");
}Tools, structured output and multi-turn conversations are the same builder
with one more call on it. Speech is transcribe: the same shape over
Whisper (OpenAI’s, or a faster-whisper server of your own) and Deepgram,
answering with every word and the moment it was said. Every call reports an ai.call event — provider,
model, token counts, duration — so Telescope can show what the models cost
without ever seeing a prompt or a key.
Re-exports§
pub use completion::Completion;pub use completion::StopReason;pub use completion::ToolCall;pub use completion::Usage;pub use config::ApiKey;pub use config::Settings;pub use fake::Fake;pub use message::Content;pub use message::Conversation;pub use message::Message;pub use message::Role;pub use provider::BoxFuture;pub use provider::Provider;pub use provider::StreamDelta;pub use provider::TextStream;pub use providers::Anthropic;pub use providers::Ollama;pub use providers::OpenAi;pub use request::Request;pub use structured::generate_as;pub use tool::DEFAULT_MAX_ROUNDS;pub use tool::Schema;pub use tool::Tool;pub use tool::Toolbox;pub use tool::run_tools;pub use transcribe::Audio;pub use transcribe::Deepgram;pub use transcribe::FakeTranscriber;pub use transcribe::Transcriber;pub use transcribe::Transcript;pub use transcribe::Transcription;pub use transcribe::Whisper;
Modules§
- completion
- What a model gives back: text, tool calls, why it stopped, what it cost.
- config
- Where the provider, the model and the key come from.
- fake
Ai::fake()— a provider that answers from a script.- message
- The conversation model, kept deliberately free of any provider’s shape.
- provider
- The provider trait and the text stream every provider produces.
- providers
- The providers that ship with the framework.
- request
- What gets asked: one request shape every provider is translated from.
- structured
- Structured output: asking for JSON and actually getting it.
- tool
- Tools: describing them, registering handlers, and running the loop.
- transcribe
- Speech to text, with the time of every word.
Structs§
- Ai
- The front door.
- Generation
- One call being assembled.