View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 代码
  • 使用 fm CLI 和 Python SDK 构建 AI 驱动的脚本

    探索在 macOS 上充分利用 Apple Foundation Models 的各种新方法。适用于 Python 的 Foundation Models SDK 支持与 Python 生态系统中的常用工具和评估包集成。了解如何使用 macOS 27 中推出的全新 fm 命令来简化脚本编写、实现模型工作流程自动化,并加速开发流程。

    章节

    • 0:00 - Introduction
    • 1:22 - Introducing the fm CLI and Python SDK
    • 3:23 - Command line tool
    • 5:02 - fm respond and structured output
    • 6:11 - Automating file management with fm
    • 8:52 - Python SDK
    • 9:42 - Prompting, tool calling and guided generation
    • 10:44 - Building an evaluation pipeline in Python
    • 15:20 - Next steps

    资源

    • Foundation Models SDK for Python on GitHub
    • Foundation Models SDK for Python Documentation on GitHub
      • 高清视频
      • 标清视频

    相关视频

    WWDC26

    • 使用 Foundation Models 框架构建智能体 App 体验
    • 将 LLM 提供平台引入 Foundation Models 框架
    • 通过专用云计算充分利用 [Model Name]
    • Foundation Models 框架的新功能
  • 搜索此视频…
    • 5:07 - Prompt the on-device model with fm respond

      $ fm respond "Provide a basic regex in Swift to parse an email address"
      # Here is a basic regex to parse an email address in Swift: [...]
      
      $ fm respond "Provide a comprehensive regex in Swift to parse an email address" --model pcc
      # [...] Here's a robust Swift implementation using 'NSRegularExpression' to validate a typical email address:
      
      $ fm respond "What app is the user using in this screenshot?" --model pcc \
      	--image Screenshot.png
      # The user is using the Mail app.
      
      $ fm schema object --name AppsIdentified --string app_names --array > schema.json 
      $ fm respond "What apps are the user actively using in this screenshot?" \
      	--image Screenshot.png --model pcc --schema schema.json
      # {"app_names": ["Messages", "Mail", "Calendar"]}
      
      $ fm respond --help
    • 7:55 - Sort files with fm respond and a schema

      fm schema object --name "TriagedFileList" \
          --string 'final_files' --array \
          --string 'draft_files' --array > /tmp/schema.json
      
      output=$(fm respond \
          --instructions "I just completed a project, and I need help triaging the latest version of the files from the previous versions. I will give you a list of files. Return a list of the latest files (i.e., all files that, you can infer from their name in the list, are the latest versions), and then return separately a list of all draft files (i.e., all files that weren't considered final)." \
          "This is the list of all files:\n\n${files_list}" \
          --schema /tmp/schema.json
      )
      
      echo "${output}" | jq -r '.final_files[]' | while read -r file; do
          cp "${DIRECTORY_TO_TRIAGE}/${file}" "${FINAL_FILES_STORAGE_DIRECTORY}"
      done
      
      echo "${output}" | jq -r '.draft_files[]' | while read -r file; do
          mv "${DIRECTORY_TO_TRIAGE}/${file}" "${DRAFT_FILES_STORAGE_DIRECTORY}"
      done
    • 8:54 - Install the Foundation Models Python SDK

      pip install apple_fm_sdk
    • 10:00 - Create a session and respond to a prompt

      import apple_fm_sdk as fm
      
      INSTRUCTIONS = "You're an AI assistant for Cupertino Mart, a grocery store with in-app ordering."
      
      async def answer_question(prompt: str) -> str:
      	session = fm.LanguageModelSession(instructions=INSTRUCTIONS)
        return await session.respond(prompt)
    • 10:21 - Define a Tool for the language model

      class GetPastOrdersTool(fm.Tool):
        name = "get_past_orders"
        description = "Retrieves information about this user's past orders."
      
        @fm.generable("Past orders query parameter")
        class Arguments:
        	number_orders: str = fm.guide("How many of the last orders to retrieve")
      
        @property
        def arguments_schema(self) -> fm.GenerationSchema:
        	return self.Arguments.generation_schema()
      
      async def call(self, args: fm.GeneratedContent) -> str:
      	number_orders = args.value(int, for_property="number_orders")
        return await Orders.load_last_orders(user_id=user_id, amount=number_orders)
    • 10:35 - Generate structured output with @fm.generable

      @fm.generable("Suggested items")
      class ItemsSuggestion:
      	item_names: list[str] = fm.guide("Names of the suggested items")
      
      INSTRUCTIONS = "You're an AI assistant tasked with returning potential grocery items that the user might be interested in."
      
      async def generate_suggested_cart_items(user_input: Optional[str]) -> ItemsSuggestion:
      	session = fm.LanguageModelSession(instructions=INSTRUCTIONS, tools=load_tools())
      	prompt = """Using the tools to load the user's previous orders, \
                    return a list of items the user has already ordered \
                    and that they might be interested in again \
                    as they're getting ready to place a new grocery order."""
      	if user_input is not None:
          prompt += f"\nAccount for the following request from the user: {user_input}"
          return await session.respond(prompt, generating=ItemsSuggestion)
    • 0:00 - Introduction
    • Overview of the Foundation Models Framework — guided generation, tool calling, and new macOS 27 features like image inputs and server model access.

    • 1:22 - Introducing the fm CLI and Python SDK
    • Two new ways to access Apple Foundation Models on macOS: the fm command line tool (pre-installed with macOS 27 for terminal-based prompting and automation) and the Foundation Models SDK for Python (for ML engineers who work more in Python than Swift).

    • 3:23 - Command line tool
    • How to use the fm command line tool — browsing available commands, starting an interactive conversation with fm chat, switching between the on-device and Private Cloud Compute models, and saving sessions to resume later.

    • 5:02 - fm respond and structured output
    • How to use fm respond for inline scripting — passing prompts and getting responses as terminal output, using the model and image options, and combining fm schema object with the schema option to produce structured JSON outputs.

    • 6:11 - Automating file management with fm
    • A practical automation demo: using fm in a shell script to intelligently sort a messy presentation folder — prompting the model with a file list to classify drafts versus finals, generating structured JSON output, and routing files to backup and archive accordingly.

    • 8:52 - Python SDK
    • Introduction to the Foundation Models SDK for Python — installation requirements (Python 3.10+, Xcode, Apple Silicon), core features mirroring the Swift framework (text and image inputs, streaming, tool calling, guided generation), and its value for ML engineers and rapid prototyping.

    • 9:42 - Prompting, tool calling and guided generation
    • How to use the Python SDK in a grocery app prototype — creating a LanguageModelSession, calling session.respond with a prompt, exposing tools for the model to fetch order history, and using the fm.generable decorator for structured output into a typed ItemsSuggestion object.

    • 10:44 - Building an evaluation pipeline in Python
    • A case study using the Python SDK with Jupyter, Pandas, and matplotlib to evaluate three prompt implementations for a cart completion feature — generating outputs with the on-device model, scoring them with a server judge model on criteria like excess items, missing items, and hallucinations, and visualizing results to guide prompt iteration.

    • 15:20 - Next steps
    • Summary of the new macOS tools and next steps: explore fm in Terminal, visit the Python SDK GitHub for example snippets, and build an evaluation pipeline to measure and improve prompt quality.

Developer Footer

  • 视频
  • WWDC26
  • 使用 fm CLI 和 Python SDK 构建 AI 驱动的脚本
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner Program
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则