How to use Foundation Models?

Asked on 06/25/2025

1 search

To use Foundation Models, you can follow these steps based on the content presented at WWDC:

  1. Import the Framework: Start by importing the Foundation Models framework into your project. This gives you access to Apple's on-device large language model.

  2. Create a Session: Use the framework to create a session. This session is where you will interact with the model.

  3. Send a Prompt: You can send prompts to the model to generate responses. This can be done with just a few lines of code. The model is optimized for tasks like text extraction, summarization, and more.

  4. Use Generable for Structured Output: If you need structured output, you can use the Generable macro to define types that the model can generate. This allows you to get structured data directly from the model.

  5. Tool Calling: The framework supports tool calling, which allows the model to autonomously call functions you define. This can be used to fetch additional information or perform actions based on the model's processing.

  6. Privacy and Performance: All processing is done on-device, ensuring user data privacy and allowing the model to work offline. The framework is built into the operating system, so it doesn't increase your app size.

For a more detailed exploration, you can refer to the sessions like Deep dive into the Foundation Models framework and Code-along: Bring on-device AI to your app using the Foundation Models framework. These sessions provide in-depth guidance on using the Foundation Models framework effectively.