帮助开发者在 iOS 26+ 中集成端侧大模型生成、工具调用与流式输出。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "foundation-models-on-device" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/foundation-models-on-device/SKILL.md 2. 保存为 ~/.claude/skills/foundation-models-on-device/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为 iOS 26+ 编写一个使用 Apple FoundationModels framework 的 Swift 示例,演示基础文本生成流程,包括模型调用、提示词传入、结果展示,以及适合 SwiftUI 应用集成的代码结构。
一份可参考的 Swift/SwiftUI 集成示例,说明如何在应用中接入端侧文本生成。
请用 Apple FoundationModels framework 说明如何使用 @Generable 定义结构化输出,生成一个“会议纪要”对象,包含标题、摘要、行动项和负责人,并给出完整 Swift 示例。
包含 @Generable 数据模型与调用代码的示例,可用于稳定生成结构化结果。
请演示在 Apple FoundationModels framework 中实现 tool calling 和 snapshot streaming:定义一个获取天气的工具,让模型根据用户问题调用它,并实时流式返回中间与最终结果,使用 Swift 编写。
一套展示工具定义、模型调用和流式更新 UI 的 Swift 实现方案。
Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with @Generable, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.
Always check model availability before creating a session:
struct GenerativeView: View {
private var model = SystemLanguageModel.default
var body: some View {
switch model.availability {
case .available:
ContentView()
case .unavailable(.deviceNotEligible):
Text("Device not eligible for Apple Intelligence")
case .unavailable(.appleIntelligenceNotEnabled):
Text("Please enable Apple Intelligence in Settings")
case .unavailable(.modelNotReady):
Text("Model is downloading or not ready")
case .unavailable(let other):
Text("Model unavailable: \(other)")
}
}
}
// Single-turn: create a new session each time
let session = LanguageModelSession()
let response = try await session.respond(to: "What's a good month to visit Paris?")
print(response.content)
// Multi-turn: reuse session for conversation context
let session = LanguageModelSession(instructions: """
You are a cooking assistant.
Provide recipe suggestions based on ingredients.
Keep suggestions brief and practical.
""")
let first = try await session.respond(to: "I have chicken and rice")
let followUp = try await session.respond(to: "What about a vegetarian option?")
Key points for instructions:
Generate structured Swift types instead of raw strings:
@Generable(description: "Basic profile information about a cat")
struct CatProfile {
var name: String
@Guide(description: "The age of the cat", .range(0...20))
var age: Int
@Guide(description: "A one sentence profile about the cat's personality")
var profile: String
}
let response = try await session.respond(
to: "Generate a cute rescue cat",
generating: CatProfile.self
)
// Access structured fields directly
print("Name: \(response.content.name)")
print("Age: \(response.content.age)")
print("Profile: \(response.content.profile)")
.range(0...20) — numeric range.count(3) — array element countdescription: — semantic guidance for generationLet the model invoke custom code for domain-specific tasks:
struct RecipeSearchTool: Tool {
let name = "recipe_search"
let description = "Search for recipes matching a given term and return a list of results."
@Generable
struct Arguments {
var searchTerm: String
var numberOfResults: Int
}
func call(arguments: Arguments) async throws -> ToolOutput {
let recipes = await searchRecipes(
term: arguments.searchTerm,
limit: arguments.numberOfResults
)
return .string(recipes.map { "- \($0.name): \($0.description)" }.joined(separator: "\n"))
}
}
…
为 Quarkus 项目执行发布前验证闭环,涵盖构建、测试、扫描与差异审查。
帮助你用 Swift、SwiftUI 与苹果新框架开发现代 iOS 应用功能