how can I use the foundation models

Asked on 06/11/2025

1 search

To use the Foundation Models framework introduced by Apple at WWDC, you can follow these steps:

  1. Import the Framework: Start by importing the Foundation Models framework into your project. This framework provides access to an on-device large language model with a convenient Swift API.

  2. Create a Session: Establish a session with the model. This session allows you to interact with the model and send prompts.

  3. Send Prompts: You can send prompts to the model to perform tasks such as text extraction, summarization, and more. The model is optimized for performance and can provide responses either as a single output or incrementally using streaming output.

  4. Use Generable and Guide Macros: For structured output, you can use the Generable and Guide macros. These allow you to define types that the model can generate, and provide natural language descriptions and constraints for the properties of these types.

  5. Tool Calling: The framework supports tool calling, which allows the model to autonomously call functions you define in Swift. This can be used to fetch up-to-date content or perform actions within your app.

  6. Privacy and Efficiency: All operations are performed on-device, ensuring user data privacy and allowing the model to function offline without increasing app size.

For a practical example, you can refer to the session Code-along: Bring on-device AI to your app using the Foundation Models framework (02:30) which covers prompt engineering and other aspects of using the framework.

If you want to dive deeper into the framework, consider watching Meet the Foundation Models framework (05:20) for guided generation and Deep dive into the Foundation Models framework (07:57) for more advanced features like dynamic schemas and tool calling.