Foundation models 怎么用

Asked on 06/12/2025

1 search

The Foundation Models framework, introduced by Apple, provides access to an on-device large language model through a convenient Swift API. This framework is available on macOS, iPadOS, iOS, and VisionOS, and it allows developers to enhance their apps with intelligent features while keeping data private and offline.

To use the Foundation Models framework, you can follow these steps:

  1. Import the Framework: Start by importing the Foundation Models framework into your project.

  2. Create a Session: Initialize a session to interact with the model. This session will handle the communication between your app and the language model.

  3. Send Prompts: Use the session to send prompts to the model. You can generate text, structured data, or even use tool calling to perform specific actions.

  4. Structured Output: The framework supports generating structured data using the Generable macro, which allows you to define Swift types that the model can generate.

  5. Tool Calling: You can define tools that the model can call to fetch additional information or perform actions, enhancing the model's capabilities beyond text generation.

For a detailed exploration of these features, you can refer to the following sessions from WWDC 2025:

These sessions provide comprehensive insights into using the Foundation Models framework, including prompt engineering, tool calling, and generating structured data.