feat(me,home): 模型推理自检 + 启动容错 + 首页假数据清理

- KangkangApp: ModelContainer 创建失败时重置本地 store 重建,
  避免 demo 阶段 schema 演进导致旧真机启动崩溃(注:生产需正式迁移)
- ModelSelfTestView: 正式的推理自检页(固定 prompt + 流式输出 + tok/s),
  仅当 LLM 模型就绪时从「模型管理」出现入口
- 删除 DEBUG-only 的 DebugAIRunner,自检转正为就绪后可见的正式入口
- HomeView: 删除写死的「今日摘记」假数据卡;问候改为按时段动态
  (早安/下午好/晚上好)+ 当天日期;影像档案数字接真实 @Query 计数
- MeView: 模型管理卡动态状态 + 关于页接真实版本号(用户改动一并纳入)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
link2026
2026-05-30 08:02:35 +08:00
parent 062c027c77
commit 910ca99f21
7 changed files with 337 additions and 267 deletions

View File

@@ -0,0 +1,119 @@
import SwiftUI
/// : LLM prompt, + tok/s
/// · ,
struct ModelSelfTestView: View {
@State private var output = ""
@State private var phase: Phase = .idle
@State private var rate: Double = 0
private enum Phase: Equatable {
case idle, loading, running, done, failed(String)
var label: String {
switch self {
case .idle: return "未开始"
case .loading: return "加载模型…"
case .running: return "推理中…"
case .done: return "完成 ✓"
case .failed(let m): return "失败:\(m)"
}
}
}
private let prompt = "用中文一句话介绍肝功能里 ALT 这个指标。"
private var isBusy: Bool { phase == .loading || phase == .running }
private var statusColor: Color {
switch phase {
case .failed: return Tj.Palette.brick
case .done: return Tj.Palette.leaf
default: return Tj.Palette.text2
}
}
var body: some View {
VStack(alignment: .leading, spacing: 16) {
VStack(alignment: .leading, spacing: 6) {
Text("测试 PROMPT")
.font(.system(size: 11, weight: .semibold))
.tracking(0.5)
.foregroundStyle(Tj.Palette.text3)
Text(prompt)
.font(.system(size: 14))
.foregroundStyle(Tj.Palette.text)
}
.padding(14)
.frame(maxWidth: .infinity, alignment: .leading)
.tjCard()
HStack {
Text(phase.label)
.font(.system(size: 13, weight: .medium))
.foregroundStyle(statusColor)
.lineLimit(1)
Spacer()
if rate > 0 {
Text(String(format: "%.1f tok/s", rate))
.font(.system(size: 12, design: .monospaced))
.foregroundStyle(Tj.Palette.text3)
}
}
Button {
Task { await run() }
} label: {
Text(isBusy ? "运行中…" : "运行推理自检").frame(maxWidth: .infinity)
}
.buttonStyle(TjPrimaryButton())
.disabled(isBusy)
ScrollView {
Text(output.isEmpty ? "(暂无输出)" : output)
.font(.system(.footnote, design: .monospaced))
.foregroundStyle(Tj.Palette.text)
.frame(maxWidth: .infinity, alignment: .leading)
.textSelection(.enabled)
.padding(12)
}
.frame(maxHeight: 280)
.background(
RoundedRectangle(cornerRadius: Tj.Radius.md, style: .continuous)
.fill(Tj.Palette.paper)
)
.overlay(
RoundedRectangle(cornerRadius: Tj.Radius.md, style: .continuous)
.strokeBorder(Tj.Palette.lineSoft, lineWidth: 1)
)
Spacer()
}
.padding(16)
.background(Tj.Palette.sand.ignoresSafeArea())
.navigationTitle("推理自检")
.navigationBarTitleDisplayMode(.inline)
}
@MainActor
private func run() async {
output = ""
rate = 0
phase = .loading
do {
try await AIRuntime.shared.prepare()
phase = .running
for try await chunk in await AIRuntime.shared.generate(prompt: prompt, maxTokens: 200) {
output += chunk.text
rate = chunk.decodeRate
}
phase = .done
} catch {
phase = .failed(error.localizedDescription)
}
}
}
#Preview {
NavigationStack { ModelSelfTestView() }
}