| Crates.io | fm-rs |
| lib.rs | fm-rs |
| version | 0.1.4 |
| created_at | 2026-01-17 21:22:17.472012+00 |
| updated_at | 2026-01-22 02:27:44.789522+00 |
| description | Rust bindings for Apple's FoundationModels.framework |
| homepage | |
| repository | https://github.com/blacktop/fm-rs |
| max_upload_size | |
| id | 2051211 |
| size | 238,640 |
Rust bindings for Apple’s FoundationModels.framework
[dependencies]
fm-rs = "0.1"
Enable the derive macro if you want compile-time schema generation:
[dependencies]
fm-rs = { version = "0.1", features = ["derive"] }
use fm_rs::{GenerationOptions, Session, SystemLanguageModel};
fn main() -> Result<(), fm_rs::Error> {
let model = SystemLanguageModel::new()?;
model.ensure_available()?;
let session = Session::with_instructions(&model, "You are a helpful assistant.")?;
let options = GenerationOptions::builder()
.temperature(0.7)
.max_response_tokens(500)
.build();
let response = session.respond("What is the capital of France?", &options)?;
println!("{}", response.content());
Ok(())
}
spawn_blocking in async runtimes.libswift_Concurrency.dylib load errors, add Swift rpaths in your binary crate’s build.rs.use std::process::Command;
fn main() {
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
if let Ok(output) = Command::new("xcrun")
.args(["--toolchain", "default", "--find", "swift"])
.output()
{
let swift_path = String::from_utf8_lossy(&output.stdout).trim().to_string();
if let Some(toolchain) = std::path::Path::new(&swift_path).parent().and_then(|p| p.parent()) {
let lib_path = toolchain.join("lib/swift/macosx");
if lib_path.exists() {
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_path.display());
}
}
}
}
For best results on-device:
See Apple’s guidance for more detail:
cargo run --example basic
cargo run --example streaming
cargo run --example tools
cargo run --example structured
cargo run --example context_compaction
See API details and advanced usage in the crate docs (docs.rs).
MIT License - see LICENSE for details.