Give me an example of how to use foundation models from an app intent
Asked on 06/13/2025
1 search
To use foundation models from an app intent, you can leverage the Foundation Models framework introduced by Apple. Here's a step-by-step example based on the session "Code-along: Bring on-device AI to your app using the Foundation Models framework":
-
Import the Framework: Start by importing the Foundation Models framework into your project.
-
Create a Session: Use the framework to create a session. This session will be used to interact with the on-device large language model.
-
Define Instructions: Use the Builder API to create instructions for the model. Instructions are a higher-level form of prompting where you define the model's job. For example, if you want the model to generate an itinerary, you can provide information about a selected landmark and include an example to guide the model's response.
-
Use Generable Types: If you have structured data, you can define it using generable types. The framework will automatically convert these types to text that the model can understand.
-
Make a Request: With your instructions and generable types set, you can make a request to the model. For instance, you can explicitly ask the model to generate an itinerary.
-
Tool Calling: Optionally, you can use tool calling to let the model autonomously choose the best points of interest or fetch additional information from external sources.
For a detailed walkthrough, you can refer to the session Code-along: Bring on-device AI to your app using the Foundation Models framework (02:30).
This approach allows you to integrate powerful AI capabilities into your app while keeping user data private, as everything runs on-device.

Explore prompt design & safety for on-device foundation models
Design generative AI experiences that leverage the strengths of the Foundation Models framework. We’ll start by showing how to design prompts for the on-device large language model at the core of Apple Intelligence. Then, we’ll introduce key ideas around AI safety, and offer concrete strategies to make your generative AI features safe, reliable, and delightful.

Code-along: Bring on-device AI to your app using the Foundation Models framework
Develop generative AI features for your SwiftUI apps using the Foundation Models framework. Get started by applying the basics of the framework to create an awesome feature. Watch step-by-step examples of how to complement the models with tools you build, stream results, and apply further optimizations for great performance.

Meet the Foundation Models framework
Learn how to tap into the on-device large language model behind Apple Intelligence! This high-level overview covers everything from guided generation for generating Swift data structures and streaming for responsive experiences, to tool calling for integrating data sources and sessions for context management. This session has no prerequisites.