feat(语音日记): DiaryAssistService.organize 转写稿整理

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
link2026
2026-06-10 06:11:55 +08:00
parent cfeb25247a
commit 5eb724ab86

View File

@@ -98,4 +98,29 @@ struct DiaryAssistService {
guard !questions.isEmpty else { throw AssistError.empty } guard !questions.isEmpty else { throw AssistError.empty }
return (Array(questions.prefix(4)), lastRate) return (Array(questions.prefix(4)), lastRate)
} }
/// 稿稿(spec 2026-06-10-voice-diary)
/// ( / ),退使,
/// suggest AIRuntime actor ,/
func organize(transcript: String) async throws -> (text: String, decodeRate: Double) {
do {
try await AIRuntime.shared.prepare()
} catch {
throw AssistError.modelNotReady
}
let prompt = DiaryAssistPrompts.organize(transcript: transcript)
var collected = ""
var lastRate: Double = 0
let stream = await AIRuntime.shared.generate(prompt: prompt, maxTokens: 400)
for try await chunk in stream {
collected += chunk.text
if chunk.decodeRate > 0 { lastRate = chunk.decodeRate }
}
let text = HealthExportService.stripThinkBlocks(collected)
.trimmingCharacters(in: .whitespacesAndNewlines)
guard !text.isEmpty else { throw AssistError.empty }
return (text, lastRate)
}
} }