2026-04-22 16:31:12 +08:00
|
|
|
from app.services.voice_confirm import (
|
|
|
|
|
build_prompt_text,
|
|
|
|
|
match_voice_choice_against_candidates,
|
|
|
|
|
parse_voice_choice,
|
|
|
|
|
)
|
feat: surgery pipeline API, video inference, voice confirm, and tests
- Add FastAPI routes for surgery start/end, results, pending confirmation (WAV upload), and health checks.
- Implement RTSP/Hikvision capture, consumable classification, session manager, MinIO/Baidu voice resolution, and DB persistence.
- Add documentation (client API, video backends, staging checklist) and sample camera/RTSP config.
- Add pytest suite (API contract, session manager, voice, repositories, pipeline persistence) and httpx dev dependency.
- Replace deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT.
- Fix SurgeryPipeline DB reads to use an explicit transaction with autobegin disabled.
Made-with: Cursor
2026-04-21 18:33:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_voice_choice_substring() -> None:
|
|
|
|
|
assert parse_voice_choice("用的是纱布对吧", ["纱布", "缝线"]) == "纱布"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_voice_choice_numeric() -> None:
|
|
|
|
|
assert parse_voice_choice("第2个", ["纱布", "缝线", "钳子"]) == "缝线"
|
|
|
|
|
|
|
|
|
|
|
2026-04-23 14:24:20 +08:00
|
|
|
def test_parse_voice_choice_ordinal_chinese() -> None:
|
|
|
|
|
opts = ["纱布", "缝线", "钳子"]
|
|
|
|
|
assert parse_voice_choice("第一个", opts) == "纱布"
|
|
|
|
|
assert parse_voice_choice("第一个。", opts) == "纱布"
|
|
|
|
|
assert parse_voice_choice("第2个", opts) == "缝线"
|
|
|
|
|
assert parse_voice_choice("第二", opts) == "缝线"
|
|
|
|
|
assert parse_voice_choice("选3", opts) == "钳子"
|
|
|
|
|
assert parse_voice_choice("选项2", ["纱布", "缝线"]) == "缝线"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_voice_choice_single_chinese_digit_with_few_options() -> None:
|
|
|
|
|
assert parse_voice_choice("一", ["纱布", "缝线"]) == "纱布"
|
|
|
|
|
assert parse_voice_choice("两", ["纱布", "缝线"]) == "缝线"
|
|
|
|
|
|
|
|
|
|
|
feat: surgery pipeline API, video inference, voice confirm, and tests
- Add FastAPI routes for surgery start/end, results, pending confirmation (WAV upload), and health checks.
- Implement RTSP/Hikvision capture, consumable classification, session manager, MinIO/Baidu voice resolution, and DB persistence.
- Add documentation (client API, video backends, staging checklist) and sample camera/RTSP config.
- Add pytest suite (API contract, session manager, voice, repositories, pipeline persistence) and httpx dev dependency.
- Replace deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT.
- Fix SurgeryPipeline DB reads to use an explicit transaction with autobegin disabled.
Made-with: Cursor
2026-04-21 18:33:54 +08:00
|
|
|
def test_parse_voice_choice_negative() -> None:
|
|
|
|
|
assert parse_voice_choice("不是", ["纱布", "缝线"]) is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_build_prompt_contains_options() -> None:
|
|
|
|
|
text = build_prompt_text([("纱布", 0.4), ("缝线", 0.3)])
|
|
|
|
|
assert "纱布" in text
|
|
|
|
|
assert "缝线" in text
|
2026-04-22 16:31:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_match_voice_against_full_candidate_list() -> None:
|
|
|
|
|
assert (
|
|
|
|
|
match_voice_choice_against_candidates(
|
|
|
|
|
"刚才用的是止血钳",
|
|
|
|
|
["纱布", "缝线", "止血钳"],
|
|
|
|
|
)
|
|
|
|
|
== "止血钳"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_match_voice_longest_candidate_first() -> None:
|
|
|
|
|
assert (
|
|
|
|
|
match_voice_choice_against_candidates(
|
|
|
|
|
"拿的一次性止血钳",
|
|
|
|
|
["止血钳", "一次性止血钳"],
|
|
|
|
|
)
|
|
|
|
|
== "一次性止血钳"
|
|
|
|
|
)
|