Foundation Models on Device
Apple FoundationModels 框架,用于设备端大语言模型(LLM)—— iOS 26+ 中的文本生成、配合 @Generable 的引导式生成、工具调用以及快照流式传输。
Install
/plugin marketplace add xu-xiang/everything-claude-code-zhThe repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.
npx skills add xu-xiang/everything-claude-code-zh --skill foundation-models-on-devicegit clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/foundation-models-on-device ~/.claude/skills/foundation-models-on-devicePersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# FoundationModels:设备端大语言模型 (iOS 26)
使用 FoundationModels 框架将 Apple 的设备端语言模型集成到应用中的模式。涵盖文本生成、使用 `@Generable` 的结构化输出、自定义工具调用以及快照流式传输 —— 全部在设备端运行,以支持隐私保护和离线使用。
## 何时激活
- 使用 Apple Intelligence 在设备端构建 AI 驱动的功能
- 在不依赖云端的情况下生成或总结文本
- 从自然语言输入中提取结构化数据
- 为特定领域的 AI 操作实现自定义工具调用
- 流式传输结构化响应以实现实时 UI 更新
- 需要隐私保护的 AI(数据不离开设备)
## 核心模式 —— 可用性检查
在创建会话(Session)之前,请务必检查模型的可用性:
```swift
struct GenerativeView: View {
private var model = SystemLanguageModel.default
var body: some View {
switch model.availability {
case .available:
ContentView()
case .unavailable(.deviceNotEligible):
Text("设备不符合 Apple Intelligence 的使用条件")
case .unavailable(.appleIntelligenceNotEnabled):
Text("请在设置中启用 Apple Intelligence")
case .unavailable(.modelNotReady):
Text("模型正在下载或尚未就绪")
case .unavailable(let other):
Text("模型不可用:\(other)")
}
}
}
```
## 核心模式 —— 基础会话
```swift
// 单轮:每次创建一个新会话
let session = LanguageModelSession()
let response = try await session.respond(to: "去巴黎旅游哪个月份比较好?")
print(response.content)
// 多轮:复用会话以保留对话上下文
let session = LanguageModelSession(instructions: """
你是一个烹饪助手。
请根据食材提供食谱建议。
建议要保持简短且实用。
""")
let first = try await session.respond(to: "我有鸡肉和米饭")
let followUp = try await session.respond(to: "那素食选择呢?")
```
提示词指令(Instructions)的关键点:
- 定义模型的角色(“你是一个导师”)
- 指定要做什么(“帮助提取日历事件”)
- 设置风格偏好(“尽可能简短地回答”)
- 添加安全措施(“对于危险请求,请回答‘我无法提供帮助’”)Details
- Skill name
foundation-models-on-device- Repository
- xu-xiang/everything-claude-code-zh
- Path
skills/foundation-models-on-device/SKILL.md- License
- MIT
- Repo updated
- 5 March 2026
FAQ
What does the Foundation Models on Device skill do?
Apple FoundationModels 框架,用于设备端大语言模型(LLM)—— iOS 26+ 中的文本生成、配合 @Generable 的引导式生成、工具调用以及快照流式传输。
How do I install the Foundation Models on Device skill?
Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Foundation Models on Device popular?
It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.
Related skills
Backend Patterns
2kxu-xiang/everything-claude-code-zh
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Coding Standards
2kxu-xiang/everything-claude-code-zh
Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
Frontend Patterns
2kxu-xiang/everything-claude-code-zh
Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.
Regex Vs LLM Structured Text
2kxu-xiang/everything-claude-code-zh
选择在解析结构化文本时使用正则表达式还是大型语言模型的决策框架——从正则表达式开始,仅在低置信度的边缘情况下添加大型语言模型。
Foundation Models on Device
2kxu-xiang/everything-claude-code-zh
苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。
Regex Vs LLM Structured Text
2kxu-xiang/everything-claude-code-zh
在解析结构化文本时,用于在正则表达式(Regex)和大型语言模型(LLM)之间进行选择的决策框架——优先使用正则表达式,仅针对低置信度的边界情况引入 LLM。
Browse the most popular Claude skills, all ai, llms & agents skills, or write your own with the skills generator.