feat: add authenticated engine processing boundary

This commit is contained in:
2026-10-31 17:36:55 +03:00
parent 193f0b4069
commit e2ba9ab451
9 changed files with 378 additions and 81 deletions
+4 -3
View File
@@ -252,7 +252,7 @@ def extract_document(document, llm_client=None, batch_id=None):
"""Извлечь паспорт одного документа, изолируя ошибки на уровне документа."""
document_id = document["id"]
batch_id = batch_id if batch_id is not None else document.get("batch_id")
elements = _decode_elements(document.get("elements_json"))
elements = _decode_elements(document.get("elements", document.get("elements_json")))
structured_text = format_elements_with_structure(elements)
raw_response = "{}"
try:
@@ -306,13 +306,14 @@ def extract_document(document, llm_client=None, batch_id=None):
return {"ok": False, "document_id": document_id, "error": str(error)}
def extract_batch(batch_id, llm_client=None, progress_callback=None):
def extract_batch(batch_id, llm_client=None, progress_callback=None, documents=None):
"""Обработать документы batch и вернуть сводку без batch-wide failure.
Optional progress callback получает (completed_count, document_result) после
каждого документа; ошибки callback не должны останавливать обработку batch.
"""
documents = db_docs.list_for_extraction(batch_id)
if documents is None:
documents = db_docs.list_for_extraction(batch_id)
results = []
for completed, document in enumerate(documents, start=1):
result = extract_document(document, llm_client=llm_client, batch_id=batch_id)