feat(Capture): 报告识别注入 Vision OCR 参考文本,提升 2B 多模态数字准确率
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
32
康康Tests/VLPromptsOCRTests.swift
Normal file
32
康康Tests/VLPromptsOCRTests.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
import Testing
|
||||
@testable import 康康
|
||||
|
||||
struct VLPromptsOCRTests {
|
||||
|
||||
@Test func emptyOCRKeepsPromptClean() {
|
||||
let p = VLPrompts.reportExtraction(ocrText: "")
|
||||
#expect(!p.contains("OCR 参考文本"))
|
||||
#expect(!p.contains("{{OCR_SECTION}}"))
|
||||
#expect(p.contains("现在请识别图片并输出 JSON"))
|
||||
}
|
||||
|
||||
@Test func ocrTextIsInjectedBeforeFinalInstruction() {
|
||||
let p = VLPrompts.reportExtraction(ocrText: "尿酸 486 208-428 μmol/L")
|
||||
#expect(p.contains("OCR 参考文本"))
|
||||
#expect(p.contains("尿酸 486"))
|
||||
let ocrPos = p.range(of: "尿酸 486")!.lowerBound
|
||||
let endPos = p.range(of: "现在请识别图片并输出 JSON")!.lowerBound
|
||||
#expect(ocrPos < endPos)
|
||||
}
|
||||
|
||||
@Test func clipKeepsShortTextIntact() {
|
||||
#expect(VLPrompts.clipOCR("短文本") == "短文本")
|
||||
}
|
||||
|
||||
@Test func clipCutsAtLineBoundary() {
|
||||
let long = Array(repeating: "指标行 1.23 mmol/L", count: 400).joined(separator: "\n")
|
||||
let clipped = VLPrompts.clipOCR(long, limit: 200)
|
||||
#expect(clipped.count < 260)
|
||||
#expect(clipped.hasSuffix("(后续内容过长已截断)"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user