foundation-models-on-device
Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+.
Machine translationRead the original Chinese text
苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。
Target: Mobile development. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original Chinese text
Topics in the source
- FoundationModels:设备端 LLM(iOS 26)
- 何时启用
- 核心模式 — 可用性检查
- 核心模式 — 基础会话
- 核心模式 — 使用 @Generable 进行引导式生成
- 1. 定义可生成类型
- 2. 请求结构化输出
- 支持的 @Guide 约束
使用 FoundationModels 框架将苹果的设备端语言模型集成到应用中的模式。涵盖文本生成、使用 @Generable 的结构化输出、自定义工具调用以及快照流式传输——全部在设备端运行,以保护隐私并支持离线使用。 使用 Apple Intelligence 在设备端构建 AI 功能 无需依赖云端即可生成或总结文本 从自然语言输入中提取结构化数据 为特定领域的 AI 操作实现自定义工具调用 流式传输结构化响应以实现实时 UI 更新 需要保护隐私的 AI(数据不离开设备) 在创建会话之前,始终检查模型可用性: 指令的关键点: 定义模型的角色("你是一位导师") 指定要做什么("帮助提取日历事件") 设置风格偏好("尽可能简短地回答") 添加安全措施("对于危险请求,回复'我无法提供帮助'") 生成结构化的 Swift 类型,而不是原始字符串: .range(0...20) — 数值范围 .count(3) — 数组元素数量 description: — 生成的语义引导 让模型调用自定义代码以执行特定领域的任务: 使用 PartiallyGenerated 类型为实时 UI 流式传输结构化响应: | 决策 | 理由 | |----------|-----------| | 设备端执行 | 隐私性——数据不离开设备;支持离线工作 | | 4,096 个令牌限制 | 设备端模型约束;跨会话分块处理大数据 | | 快照流式传输(非增量) | 对结构化输出友好;每个快照都是一个完整的部分状态 | | @Generable 宏 | 为结构化生成提供编译时安全性;自动生成 PartiallyGenerated 类型 | | 每个会话单次请求 | isResponding 防止并发请求;如有需要,创建多个会话 | | response.content(而非 .output) | 正确的 API——始终通过 .content 属性访问结果 | 在创建会话之前始终检查 model.availability——处理所有不可用的情况 使用 instructions 来引导模型行为——它们的优先级高于提示词 在发送新请求之前检查 isResponding——会话一次处理一个请求 通过 response.content 访问结果——而不是 .output 将大型输入分块处理——4,096 个令牌的限制适用于指令、提示词和输出的总和 对于结构化输出使用 @Generable——比解析原始字符串提供更强的保证 使用 GenerationOptions(temperature:) 来调整创造力(值越高越有创意) 使用 Instruments 进行监控——使用 Xcode Instruments 来分析请求性能 未先检查 model.availability 就创建会话 发送超过 4,09
This is an excerpt. Refer to the complete source and its current requirements.
- Source repository
- affaan-m/ECC
- Source file
- docs/zh-CN/skills/foundation-models-on-device/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:50.406Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.