Foundation Models on Device

Apple FoundationModels 框架,用于设备端大语言模型(LLM)—— iOS 26+ 中的文本生成、配合 @Generable 的引导式生成、工具调用以及快照流式传输。

2,037 stars 332 forksAI, LLMs & Agents Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill foundation-models-on-device
Manual install
git 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-device

Personal 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)的关键点:
- 定义模型的角色(“你是一个导师”)
- 指定要做什么(“帮助提取日历事件”)
- 设置风格偏好(“尽可能简短地回答”)
- 添加安全措施(“对于危险请求,请回答‘我无法提供帮助’”)
Read the full skill on GitHub

Details

Skill name
foundation-models-on-device
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

Browse the most popular Claude skills, all ai, llms & agents skills, or write your own with the skills generator.