需通过 cargo add 显式开启 llama 等模型 feature,否则无法使用对应模型;示例依赖 tokio full feature 异步运行时;Fusor 仍处早期开发阶段,README 明确不建议用于生产。
kalosm
floneumApache-2.0活跃维护用 Rust 写的本地 AI 模型运行时,支持 Llama、Mistral 等模型的推理、约束生成和语音转写,方便在本地快速搭建可控的 AI 应用。
Instant, controllable, local pre-trained AI models in Rust
cargo new kalosm-hello-world
cd ./kalosm-hello-world
cargo add kalosm --features llama
cargo add tokio --features full
cargo run --releaseREADME 未给出具体显存或 CPU 要求;模型表标注 Llama、Mistral、Phi、Whisper、Segment Anything、Bert 均支持 GPU 加速,Fusor 面向 CPU 与 WebGPU 加速器。
Rust 本地预训练 AI 模型接口库,统一调用语言、音频、图像模型
用 Rust 写的本地 AI 模型运行时,支持 Llama、Mistral 等模型的推理、约束生成和语音转写,方便在本地快速搭建可控的 AI 应用。
核心能力
- 统一接口调用 Llama、Mistral、Phi、Whisper、Bert 等模型
- 用 derive(Parse, Schema) 约束输出为任意 Rust 类型
- 支持从 txt、pdf、docx 等提取并分块检索上下文
- 支持麦克风或文件音频转写与网页抓取
- Fusor 后端用 e-graph 编译器融合算子生成优化内核
容易踩的坑
- kalosm-0.4.0kalosm-0.4最新正式版2025-02-09 · 2025-02-09 23:49 UTC
Introducing Kalosm 0.4: A Local-First AI Meta-Framework for Rust
Kalosm is a simple, local first interface for pre-trained language, audio, and image models written in Rust. It is built on top of the candle library for ML inference. Kalosm makes it easy to run quantized models on your local machine accelerated by cuda or metal. Whether you’re building a chatbot, a transcription tool, or an image processing application, Kalosm 0.4 brings major improvements to help you get started quickly and efficiently.
In this release, we’re excited to announce:
- A Simplified API for language models, tasks, and chat sessions
- Extended support for remote models via OpenAI and Anthropic adapters with structured generation
- Single-file model loading that consolidates model weights, tokenizer, and chat template metadata into one GGUF file
- Improved whisper transcription with word-level timestamps using dynamic time warping
Simplified LLM API
One of the biggest improvements in Kalosm 0.4 is the streamlined API for interacting with local large language models. Developers can now configure chat sessions and tasks with a series of builder methods until the first message is added. This flexibility simplifies the code and makes your applications easier to maintain.
For example, here’s how you can set up a chat session with a system prompt:
use kalosm::language::*; // Create a new chat-capable Llama model let model = Llama::new_chat().await?; // Configure a chat session with a system prompt let mut chat = model .chat() .with_system_prompt("The assistant will act like a pirate"); loop { // Get user input and stream the model’s response to stdout chat(&prompt_input("\n> ")?) .to_std_out() .await?; }Similarly, the task API now supports automatic constraint inference. By deriving parsing and schema traits on your data types, you can easily generate concrete types from your language model:
use kalosm::language::*; /// A fictional account holder #[derive(Schema, Parse, Clone, Debug)] struct Account { /// A brief summary of the account holder #[parse(pattern = r"[a-zA-Z,.?!\d ]{1,80}")] summary: String, /// The account holder’s name (full name or pseudonym) #[parse(pattern = "[a-zA-Z ]{1,20}")] name: String, /// The account holder’s age #[parse(range = 1..=100)] age: u8, } // Create a small reasoning-focused model let llm = Llama::phi_3().await?; // Create a task for generating accounts, with automatic type-based constraint inference let create_account = llm .task("You generate accounts based on a description of the account holder") .typed(); // Generate an account from a natural language prompt let account: Account = create_account( "Candice is the CEO of a fortune 500 company. She is 30 years old." ).await?; println!("Generated Account: {account:?}");
OpenAI and Anthropic Support with Structured Generation
Kalosm 0.4 extends its support for remote models by integrating with the OpenAI and Anthropic chat APIs. Now you can use Kalosm’s structured generation even when working with remote chat models. Unfortunately Anthropic currently doesn't support structured generation, so support for tasks with Anthropic models is currently limited.
To work with OpenAI models, enable the
openaifeature and set your API key via theOPENAI_API_KEYenvironment variable. Then create a model adapter:// Create a chat model adapter for OpenAI-compatible models let llm = OpenAICompatibleChatModel::builder() .with_gpt_4o_mini() .build(); // Use the adapter just like any other chat model let generate_character = llm .task("You generate accounts based on a description of the account holder") .typed(); let account: Account = generate_character( "Candice is the - kalosm-0.3.02024-08-21 · 2024-08-21 22:00 UTC
查看更新说明
Kalosm 0.3
Kalosm 0.3 makes it significantly easier to use structured generation, improves transcription, and makes it possible to track model download progress. It also includes performance improvements for text generation and transcription models along with parser improvements
Performance Improvements
The new version of Kalosm includes significant performance improvements for llama, mistral, and phi models. We have also developed sampler aware structured generation which lets us skip parsing most tokens in loose structures. Performance should be between 2-4x as fast depending on your usecase:
Demo Kalosm 0.2 Kalosm 0.3 Text generation Structured Generation Structured Generation Improvements
Structured generation is both easier and faster in 0.3. Many structured generation tasks can use json. If you just need a json parser, kalosm 0.3 lets you derive the parser from your data:
use kalosm::language::*; /// A fictional character #[derive(Parse, Schema, Clone, Debug)] struct Character { /// The name of the character #[parse(pattern = "[A-Z][a-z]{2,10} [A-Z][a-z]{2,10}")] name: String, /// The age of the character #[parse(range = 1..=100)] age: u8, /// A description of the character #[parse(pattern = "[A-Za-z ]{40,200}")] description: String, }Then you can build a task that generates the character:
#[tokio::main] async fn main() { // First create a model. Chat models tend to work best with structured generation let model = Llama::new_chat().await.unwrap(); // Then create a task with the parser as constraints let task = Task::builder_for::<Character>("You generate realistic JSON placeholders for characters") .build(); // Finally, run the task let mut stream = task.run("Create a random character", &model); stream.to_std_out().await.unwrap(); let character = stream.await.unwrap(); println!("{character:?}"); }Along with the parser, you can also derive a json schema that matches the parser which is useful for function calling models.
You can read more about how structured generation works in kalosm in our last blog post.
Streaming Voice Transcription
Kalosm 0.3 adds support for transcribing audio streams like microphone in chunks based on voice activity. You can now read the audio stream directly from the microphone and transcribe it as voices are detected:
// Create a new whisper model. let model = Whisper::new().await.unwrap(); // Stream audio from the microphone let mic = MicInput::default(); let stream = mic.stream().unwrap(); // Transcribe the audio into text in chunks based on voice activity. let mut text_stream = stream.transcribe(model); // Finally, print the text to the console text_stream.to_std_out().await.unwrap();Model Progress
Loading models is now async with a callback for loading progress:
let model = Bert::builder() // build with loading handler lets you track the progress of the model loading .build_with_loading_handler(|loading| match loading { ModelLoadingProgress::Downloading { source, start_time, progress, } => { let elapsed = start_time.elapsed(); println!("Downloading model from {source}...{progress}% (elapsed {elapsed:?})"); - v0.2.00.2.0pre-release2023-09-12 · 2023-09-12 00:48 UTC
查看更新说明
Floneum 0.2 is here! Here are some major features in the new release:
- Improved Web Scraping
- Reading Website Feeds
- Automated Browsing Plugins
- Sharing Workflows on the Cloud
- Plugin Examples
- Rewritten UI in Dioxus!
- Package Manger
- Floneum CLI
- Nightly Builds
You can read the full release notes in the 0.2 release post
- nightly-7-23-2023Nightly-7-23-2023pre-release2023-07-24 · 2023-07-24 03:32 UTC
这个版本没有写更新说明。
- v0.1.00.1.0pre-release2023-07-12 · 2023-07-12 15:21 UTC
查看更新说明
The first pre-release of Floneum. This is a pre release, there will be bugs. If you run into any bugs, you can report them on the discord or open a github issue
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Kalosm is an ecosystem of crates that make it easy to develop applications that use local or remote AI models. There are two main projects in this repo:
- Kalosm: A simple interface for pre-trained models in rust
- Fusor: A compiler-backed runtime for quantized ML inference on CPUs and WebGPU accelerators
Kalosm
Kalosm is a simple interface for pre-trained models in Rust. It makes it easy to interact with pre-trained, language, audio, and image models.
Model Support
Kalosm supports a variety of models. Here is a list of the models that are currently supported:
| Model | Modality | Size | Description | Quantized | GPU Accelerated | Example |
|---|---|---|---|---|---|---|
| Llama | Text | 1b-70b | General purpose language model | ✅ | ✅ | llama 3 chat |
| Mistral | Text | 7-13b | General purpose language model | ✅ | ✅ | mistral chat |
| Phi | Text | 2b-4b | Small reasoning focused language model | ✅ | ✅ | phi 3 chat |
| Whisper | Audio | 20MB-1GB | Audio transcription model | ✅ | ✅ | live whisper transcription |
| Segment Anything | Image | 50MB-400MB | Image segmentation model | ✅ | ✅ | Image Segmentation |
| Bert | Text | 100MB-1GB | Text embedding model | ✅ | ✅ | Semantic Search |
Utilities
Kalosm also supports a variety of utilities around pre-trained models. These include:
- Extracting, formatting and retrieving context for LLMs: Extract context from txt/html/docx/md/pdf chunk that context then search for relevant context with vector database integrations
- Transcribing audio from your microphone or file
- Crawling and scraping content from web pages
Structured Generation
Kalosm supports structured generation with arbitrary parsers. It uses a custom parser engine and sampler and structure-aware acceleration to make structure generation even faster than uncontrolled text generation. You can take any rust type and add #[derive(Parse, Schema)] to make it usable with structured generation:
use kalosm::language::*;
/// A fictional character
#[derive(Parse, Schema, Clone, Debug)]
struct Character {
/// The name of the character
#[parse(pattern = "[A-Z][a-z]{2,10} [A-Z][a-z]{2,10}")]
name: String,
/// The age of the character
#[parse(range = 1..=100)]
age: u8,
/// A description of the character
#[parse(pattern = "[A-Za-z ]{40,200}")]
description: String,
}
#[tokio::main]
async fn main() {
// First create a model. Chat models tend to work best with structured generation
let model = Llama::phi_3().await.unwrap();
// Then create a task with the parser as constraints
let task = model.task("You generate realistic JSON placeholders for characters")
.typed();
// Finally, run the task
let mut stream = task(&"Create a list of random characters", &model);
stream.to_std_out().await.unwrap();
let characters: [Character; 10] = stream.await.unwrap();
println!("{characters:?}");
}
https://github.com/user-attachments/assets/8900f57d-55c8-4d4a-a67b-73beab1e5155
In addition to regex, you can provide your own grammar to generate structured data. This lets you constrain the response to any structure you want including complex data structures like JSON, HTML, and XML.
Kalosm Quickstart!
This quickstart will get you up and running with a simple chatbot. Let's get started!
A more complete guide for Kalosm is available on the Kalosm website, and examples are available in the examples folder.
- Install rust
- Create a new project:
cargo new kalosm-hello-world
cd ./kalosm-hello-world
- Add Kalosm as a dependency
cargo add kalosm --features llama
cargo add tokio --features full
- Add this code to your
main.rsfile
use kalosm::language::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let model = Llama::phi_3().await?;
let mut chat = model.chat()
.with_system_prompt("You are a pirate called Blackbeard");
loop {
chat(&prompt_input("\n> ")?)
.to_std_out()
.await?;
}
}
- Run your application with:
cargo run --release
Fusor
⚠️ Fusor is still early in development and is not ready for production use. It is the local inference backend used by Kalosm's model crates.
Fusor is a compiler-backed CPU and WebGPU runtime for quantized ML inference. It loads GGUF models and uses an e-graph compiler to fuse operation chains into optimized kernels without requiring model authors to write shader code. For example, this expression can compile into one kernel:
fn exp_add_one(tensor: Tensor<2, f32>) -> Tensor<2, f32> {
1. + (-tensor).exp()
}
Community
If you are interested in either project, you can join the discord to discuss the project and get help.
Contributing
- Report issues on our issue tracker.
- Help other users in the discord
- If you are interested in contributing, feel free to reach out on discord