feat/w2-ai-foundation #1
Reference in New Issue
Block a user
Delete Branch "feat/w2-ai-foundation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
按 W2 plan Task 5 落地推理串行化骨架: - TokenChunk: Sendable struct (text + decodeRate tok/s) - AIRuntime: actor 单例 - Status: notReady / loading / ready / error(msg) - prepare() async throws: 幂等加载,失败回滚 status - generate(prompt:maxTokens:) -> AsyncThrowingStream: 流式输出 跨 actor 边界用 snapshot 模式捕获 self.status/llmSession - lastDecodeRate: 给 UI 顶部条 / Live Activity 取 - AIRuntimeError: LocalizedError, 三种 case WIP: Build will fail until Task 6 lands LLMSession (intentional). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>W2 plan Task 6 写的 LLMSession 草稿在 4 处与真实 API 不符: - container.perform 的 context 是具体 ModelContext struct - MLXLMCommon.generate 是顶层函数,只 try 不 await,返回 AsyncStream 非 Throwing - Generation 有第三个 case .toolCall,switch 必须穷举 - GenerateParameters 需要 maxTokens,且 temperature/topP 是 Float - 取消传播需 continuation.onTermination = { _ in task.cancel() } 本笔记含完整修正版 LLMSession.swift,Task 6 implementer 必用此为准。 参考:mlx-swift-examples tag 2.29.1,commit 9bff95ca。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>按 W2 plan Task 6 + docs/superpowers/notes/2026-05-25-mlx-api-corrections.md 落地 LLM 推理底座: - actor LLMSession 包装 MLXLLM.ModelContainer - load(folderURL:) 用 ModelConfiguration(directory:) + LLMModelFactory.shared.loadContainer - generate(prompt:maxTokens:) 返回 AsyncThrowingStream<TokenChunk, Error> - 内部 container.perform { (context: ModelContext) in ... } 拿到模型上下文 - UserInput → processor.prepare → MLXLMCommon.generate(顶层函数, AsyncStream) - Generation switch 穷举 3 个 case(chunk / info / toolCall) - maxTokens 通过 GenerateParameters 传递,温度 0.6 topP 0.9 - 取消传播:continuation.onTermination 同步 task.cancel() - 每 chunk yield 时计算 tok/s decodeRate API 基线:mlx-swift-examples tag 2.29.1, commit 9bff95ca。 需用户手动: 1. Xcode 把 LLMSession.swift 拖入 体己 target (AI group) 2. ⌘B 验证 AIRuntime 不再报 "Cannot find LLMSession" 3. 把 ~/tiji-models/Qwen3-1.7B-4bit/ 拷到模拟器沙盒 Application Support/Models/ 4. Task 7 (DebugAIRunner) 才能跑通 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>项目开启了 -default-isolation=MainActor upcoming feature,导致: 1. static let shared 默认被视为 MainActor 隔离,即使 class 标了 @unchecked Sendable,从其他 actor(如 AIRuntime)同步访问仍报 "Expression is 'async' but is not marked with 'await'". 修法:ModelStore.shared 和 FileVault.shared 都加 nonisolated(unsafe) 修饰,明确"任何隔离上下文都可同步访问"。 2. AIRuntime.generate() 内的 Task { ... } 继承 AIRuntime actor 隔离, self.recordRate 是同 actor 内部调用,不需要 await,否则报 "No 'async' operations occur within 'await' expression". 修法:去掉冗余的 await。 ** BUILD SUCCEEDED ** 已验证。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>数据层(spec 2026-05-26): - UserProfile @Model:核心 4 项 + 健康背景 + 用药,SwiftData 单例(loadOrCreate) - Indicator 加 seriesKey: String?,标识长期指标分组('bp.systolic' 等) - MonitorMetric enum 8 case:血压(2 field 拆 2 Indicator)/ 空腹+餐后血糖 / 体重 / 体温 / 心率 / SpO2 / 身高 - effectiveRange(for:profile:) 实现 1 条 Profile-aware 规则: age >= 65 时 bp.systolic 上限 140→150 - KangkangApp schema 加 UserProfile.self 测试 17 个全绿(UserProfile 6 + MonitorMetric 11);schema 烟测扩 2(seriesKey roundtrip + UserProfile persist)。 UI 层 + Timeline 合并下个 commit。主体:多语言支持(简体中文源 + 英/日/韩) - 基础设施:Localizable.xcstrings(String Catalog,sourceLanguage=zh-Hans) + pbxproj developmentRegion/knownRegions 注册 en/ja/ko - 全部硬编码 Locale("zh_CN") → Locale.current;中文 dateFormat → Date.FormatStyle(跟随系统) - UI 中文字面量统一为 String(appLoc:)(显式绑定所选语言 bundle+locale,即时切换) Text 字面量走环境 \.locale + Bundle 重定向 - 549 个 catalog key 全部 en/ja/ko 翻译完成(0 未翻译) - App 内语言切换:我的 → 语言(LanguageManager + 即时生效,无需重启) - 双用预设(症状/监测指标/慢病)本地化:static→computed 避免缓存 注:本提交为 WIP,一并打包了并行进行的功能模块 (HealthExport 健康导出、Security/Face ID 锁、DiaryAssist 日记 AI 辅助) 及 App 图标、CLAUDE.md、docs/scripts。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>Pull request closed