fix(ревью#2): db_docs→_db + classify_raw в MemRepo + try/except в build_classify_prompt

This commit is contained in:
2026-06-28 09:40:00 +04:00
parent 8a804da494
commit d8e8b35092
4 changed files with 89 additions and 23 deletions
+7 -7
View File
@@ -92,8 +92,8 @@ def classify_batch(batch_id, llm_client=None, repo=None):
_llm = llm_client if llm_client else _get_classify_client()
# Сбросить статус — allow re-classify after file changes
db_docs.reset_classify_status(batch_id)
pending = db_docs.list_pending(batch_id)
_db.reset_classify_status(batch_id)
pending = _db.list_pending(batch_id)
if not pending:
return {"ok": False, "error": "no pending documents"}
@@ -110,24 +110,24 @@ def classify_batch(batch_id, llm_client=None, repo=None):
try:
# Stage 1: garbage by filename (0 tokens)
if _is_garbage_by_filename(doc["filename"]):
db_docs.set_classify_garbage(doc["id"], "filename_regex")
_db.set_classify_garbage(doc["id"], "filename_regex")
garbage += 1
return True
# Stage 2: garbage by header keywords (0 tokens)
text = _smart_extract(doc["elements_json"])
if _is_garbage_by_header(text):
db_docs.set_classify_garbage(doc["id"], "header_keywords")
_db.set_classify_garbage(doc["id"], "header_keywords")
garbage += 1
return True
# Stage 3: LLM classification (only for remaining)
db_docs.set_classify_processing(doc["id"]) # crash recovery marker
_db.set_classify_processing(doc["id"]) # crash recovery marker
result, raw, needed_fix = _call_llm_classify(text, _llm)
json_total += 1
if needed_fix:
json_fixes += 1
db_docs.set_classification(
_db.set_classification(
doc["id"],
result.get("doc_type", "other"),
result.get("own_number"),
@@ -139,7 +139,7 @@ def classify_batch(batch_id, llm_client=None, repo=None):
)
return True
except Exception as e:
db_docs.set_classify_failed(doc["id"], str(e))
_db.set_classify_failed(doc["id"], str(e))
return False
with ThreadPoolExecutor(max_workers=MAX_WORKERS) as pool: