pub struct SystemLanguageModel { /* private fields */ }Expand description
The system language model provided by Apple Intelligence.
This is the main entry point for using on-device AI capabilities.
Use SystemLanguageModel::new() to get the default model.
§Example
use fm_rs::SystemLanguageModel;
let model = SystemLanguageModel::new()?;
if model.is_available() {
println!("Model is ready to use!");
}Implementations§
Source§impl SystemLanguageModel
impl SystemLanguageModel
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates the default system language model.
§Errors
Returns an error if the model cannot be created or if FoundationModels
is not available on the device.
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Checks if the model is available for use.
Returns true if the model is available and ready to generate responses.
Sourcepub fn availability(&self) -> ModelAvailability
pub fn availability(&self) -> ModelAvailability
Gets the current availability status of the model.
This provides more detailed information about why the model might not be available.
Sourcepub fn ensure_available(&self) -> Result<()>
pub fn ensure_available(&self) -> Result<()>
Returns a reason-specific error if the model is unavailable.
Sourcepub fn token_usage_for(&self, prompt: &str) -> Result<TokenUsage>
pub fn token_usage_for(&self, prompt: &str) -> Result<TokenUsage>
Returns token usage for a prompt.
Uses platform token-usage APIs when available in both the build SDK and runtime. Otherwise returns a heuristic estimate.
Sourcepub fn token_usage_for_tools(
&self,
instructions: &str,
tools: &[Arc<dyn Tool>],
) -> Result<TokenUsage>
pub fn token_usage_for_tools( &self, instructions: &str, tools: &[Arc<dyn Tool>], ) -> Result<TokenUsage>
Returns token usage for session instructions and tool definitions.
Tool definitions are serialized from the Rust Tool trait objects.
Uses platform token-usage APIs when available in both the build SDK and runtime.
Otherwise returns a heuristic estimate.