Crate fm_bindings

Crate fm_bindings 

Source
Expand description

§Foundation Models Bindings for Rust

Rust bindings for Apple’s Foundation Models framework, providing access to on-device large language models (LLMs) that power Apple Intelligence.

§Requirements

  • macOS 26+ or iOS 26+
  • Apple Intelligence enabled in System Settings

§Features

  • Blocking Response: Get complete responses with response()
  • Streaming Response: Get real-time incremental updates with stream_response()
  • Type-safe error handling with Result<T, Error>
  • Zero-copy FFI layer for optimal performance

§Examples

§Blocking Response

use fm_bindings::LanguageModelSession;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = LanguageModelSession::new()?;
    let response = session.response("What is Rust?")?;
    println!("{}", response);
    Ok(())
}

§Streaming Response

use fm_bindings::LanguageModelSession;
use std::io::{self, Write};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = LanguageModelSession::new()?;

    session.stream_response("Tell me a story", |chunk| {
        print!("{}", chunk);
        let _ = io::stdout().flush();
    })?;

    println!(); // newline after stream
    Ok(())
}

Structs§

LanguageModelSession
A session for interacting with Apple’s Foundation Models

Enums§

Error
Errors that can occur when using Foundation Models

Type Aliases§

Result
Result type alias for Foundation Models operations