Fm::SystemLanguageModel
The system language model provided by Apple Intelligence.
This is the main entry point for using on-device AI capabilities.
model = Fm::SystemLanguageModel.new
if model.available?
puts "Model is ready!"
end
You can also specify use case and guardrails:
model = Fm::SystemLanguageModel.new(
use_case: Fm::UseCase::ContentTagging,
guardrails: Fm::Guardrails::PermissiveContentTransformations
)
Constructors
new(*, use_case : UseCase = UseCase::General, guardrails : Guardrails = Guardrails::Default)
SourceInstance methods
finalize
SourceReturns the token usage for a given prompt string.
Requires macOS 26.4+ at runtime. Returns nil if the API is
unavailable on the current OS version.
if tokens = model.token_usage_for("Hello, world!")
puts "Tokens: #{tokens}"
end
Returns the token usage for instructions and tools configuration.
Requires macOS 26.4+ at runtime. Returns nil if the API is
unavailable on the current OS version.
if tokens = model.token_usage_for_tools("Be helpful.", tools_json)
puts "Tokens: #{tokens}"
end
Blocks until the model becomes available or the timeout expires.
Useful when the model is still downloading (ModelNotReady).
Raises TimeoutError if the model is still not available after
the given timeout.
model = Fm::SystemLanguageModel.new
model.wait_until_available(timeout: 60.seconds)
puts "Model is ready!"