fm.cr
Crystal bindings for Apple's FoundationModels framework. Run on-device AI powered by Apple Intelligence directly from Crystal.
Requires macOS 26+ (Tahoe) with Apple Intelligence enabled.
Overview
fm.cr provides a Crystal interface to Apple's on-device language model through a Swift FFI bridge. It supports text generation, streaming, structured output with JSON schemas, tool calling, and context management -- all running locally on Apple Silicon.
Quick Links
- Getting Started -- Installation, prerequisites, and your first program
- Basic Usage -- Models, sessions, and generating responses
- API Reference -- Complete API documentation
Features
- Text Generation -- Synchronous and streaming responses
- Structured Output -- Type-safe responses using
Generableor raw JSON schemas - Tool Calling -- Extend model capabilities with custom tools
- Context Management -- Transcript export, token estimation, and automatic compaction
- Session Restore -- Save and restore conversation state via transcripts
Installation
Add fm.cr to your shard.yml:
dependencies:
fm:
github: hahwul/fm.cr
Then run:
shards install
The native Swift FFI library is built automatically via the postinstall script.