feat(backend): deliver Phase 3 document and voice integration
Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
This commit is contained in:
@@ -149,7 +149,9 @@ class OpenRouterVision:
|
||||
try:
|
||||
native = json.loads(content)
|
||||
choices = native.get("choices")
|
||||
if not choices or not isinstance(choices, list):
|
||||
if not isinstance(choices, list) or len(choices) != 1:
|
||||
raise ExtractionError("Vision transcription incomplete or blocked")
|
||||
if choices[0].get("finish_reason") not in (None, "stop"):
|
||||
raise ExtractionError("Vision transcription incomplete or blocked")
|
||||
message = choices[0].get("message", {})
|
||||
raw_text = message.get("content", "")
|
||||
@@ -168,14 +170,14 @@ class OpenRouterVision:
|
||||
if "ordinal" not in b or type(b["ordinal"]) is not int:
|
||||
b["ordinal"] = i
|
||||
transcript = Transcription.model_validate(raw_dict)
|
||||
if not transcript.complete or transcript.warnings or not transcript.blocks:
|
||||
raise ExtractionError("Vision transcription incomplete or uncertain")
|
||||
if not transcript.blocks:
|
||||
raise ExtractionError("Vision transcription has no candidate blocks")
|
||||
if len(transcript.blocks) > extraction["max_extracted_blocks"]:
|
||||
raise ExtractionError("Vision block limit exceeded")
|
||||
blocks = []
|
||||
for index, block in enumerate(transcript.blocks):
|
||||
locator = block.source_locator if block.source_locator and block.source_locator.startswith(section + "/") else f"{section}/block/{index + 1}"
|
||||
if unreadable(block.text) or any("unreadable" in w.lower() or "ناخوانا" in w for w in block.warnings):
|
||||
if unreadable(block.text):
|
||||
raise ExtractionError("Vision reports unreadable source regions")
|
||||
blocks.append(block.model_copy(update={
|
||||
"ordinal": index,
|
||||
@@ -185,6 +187,10 @@ class OpenRouterVision:
|
||||
"source_locator": locator,
|
||||
"search_text": normalize_search_text(block.text, processing_profile["normalizer"])
|
||||
}))
|
||||
# Recognition diagnostics belong to the exact review candidate.
|
||||
warnings = transcript.warnings + (() if transcript.complete else ("Vision recognition incomplete; completeness review required",))
|
||||
if warnings:
|
||||
blocks = [b.model_copy(update={"warnings": b.warnings + warnings}) for b in blocks]
|
||||
return tuple(blocks)
|
||||
except (KeyError, TypeError, ValueError, AttributeError) as exc:
|
||||
if isinstance(exc, ExtractionError):
|
||||
|
||||
Reference in New Issue
Block a user