v1.0.175: виртуальные группы + classify_raw + stepper

This commit is contained in:
2026-06-24 17:06:25 +04:00
parent b5d35f57fc
commit 475d0b8dc7
7 changed files with 114 additions and 25 deletions
+6 -6
View File
@@ -31,15 +31,14 @@ LLM_MODEL = "gpt-oss-120b"
def _call_llm_classify(header_text):
"""
Прямой вызов LLM для классификации ОДНОГО документа.
Не использует общий call_llm() из services/llm.py — здесь свой промпт и формат ответа.
Возвращает распарсенный JSON dict с полями: doc_type, own_number, parent_number, doc_date, counterparty, confidence.
Возвращает (parsed_dict, raw_text).
"""
prompt, _ = build_classify_prompt(header_text)
payload = {
"model": LLM_MODEL,
"messages": [{"role": "user", "content": prompt}],
"max_tokens": 1000, # достаточно для JSON с длинными названиями
"temperature": 0.1, # минимальная температура для детерминированности
"max_tokens": 1000,
"temperature": 0.1,
}
with httpx.Client(http2=True, timeout=60, verify=False) as client:
resp = client.post(
@@ -50,7 +49,7 @@ def _call_llm_classify(header_text):
data = resp.json()
raw = data.get("choices", [{}])[0].get("message", {}).get("content", "")
return _safe_json_parse(raw)
return _safe_json_parse(raw), raw
def classify_batch(batch_id):
@@ -74,7 +73,7 @@ def classify_batch(batch_id):
"""Классифицировать один документ: выжимка → LLM → сохранить результат."""
try:
text = _smart_extract(doc["elements_json"])
result = _call_llm_classify(text)
result, raw = _call_llm_classify(text)
db_docs.set_classification(
doc["id"],
result.get("doc_type", "other"),
@@ -82,6 +81,7 @@ def classify_batch(batch_id):
result.get("parent_number"),
result.get("doc_date"),
result.get("counterparty"),
classify_raw=raw,
)
return True
except Exception as e: