v1.0.176: classify_input + elements_json в промежуточных результатах
This commit is contained in:
+14
-1
@@ -109,11 +109,24 @@ window.toggleClassifyDetail = async function(i) {
|
||||
if (qData.doc_date) html += '<span><b>Дата:</b> ' + escHtml(qData.doc_date) + '</span>';
|
||||
if (qData.counterparty) html += '<span><b>Контрагент:</b> ' + escHtml(qData.counterparty) + '</span>';
|
||||
html += '</div>';
|
||||
if (qData.classify_input) {
|
||||
html += '<details style="margin-top:4px;"><summary style="cursor:pointer;color:var(--brand-primary);">📤 Текст отправленный в LLM</summary>';
|
||||
html += '<pre style="font-size:10px;max-height:150px;overflow:auto;background:#fff;padding:4px;border-radius:3px;margin-top:2px;">' + escHtml(qData.classify_input) + '</pre>';
|
||||
html += '</details>';
|
||||
}
|
||||
if (qData.classify_raw) {
|
||||
html += '<details style="margin-top:4px;"><summary style="cursor:pointer;color:var(--brand-primary);">Сырой ответ LLM</summary>';
|
||||
html += '<details style="margin-top:4px;"><summary style="cursor:pointer;color:var(--brand-primary);">📥 Сырой ответ LLM</summary>';
|
||||
html += '<pre style="font-size:10px;max-height:150px;overflow:auto;background:#fff;padding:4px;border-radius:3px;margin-top:2px;">' + escHtml(qData.classify_raw) + '</pre>';
|
||||
html += '</details>';
|
||||
}
|
||||
if (qData.elements_json) {
|
||||
var ej = qData.elements_json;
|
||||
if (typeof ej === 'object' && ej.Value) ej = ej.Value;
|
||||
var ejStr = typeof ej === 'string' ? ej : JSON.stringify(ej, null, 2);
|
||||
html += '<details style="margin-top:4px;"><summary style="cursor:pointer;color:var(--brand-primary);">📄 Распарсенные элементы (JSON)</summary>';
|
||||
html += '<pre style="font-size:10px;max-height:200px;overflow:auto;background:#fff;padding:4px;border-radius:3px;margin-top:2px;">' + escHtml(ejStr.substring(0, 5000)) + (ejStr.length > 5000 ? '\n... (обрезано)' : '') + '</pre>';
|
||||
html += '</details>';
|
||||
}
|
||||
} else if (qData.classify_status === 'failed') {
|
||||
html += '<span style="color:var(--destructive);">✗ Ошибка классификации: ' + escHtml(qData.error_message || '?') + '</span>';
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ from db.connection import DB_CONFIG, execute
|
||||
db_prompts.seed_defaults()
|
||||
# Schema migration: classify_raw column (idempotent)
|
||||
execute("ALTER TABLE documents ADD COLUMN IF NOT EXISTS classify_raw text")
|
||||
execute("ALTER TABLE documents ADD COLUMN IF NOT EXISTS classify_input text")
|
||||
|
||||
# ── DB modules ────────────────────────────────────────────────────────────
|
||||
from db import supplements as db_supplements
|
||||
@@ -155,6 +156,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"counterparty": doc.get("counterparty"),
|
||||
"classify_status": doc.get("classify_status"),
|
||||
"classify_raw": doc.get("classify_raw"),
|
||||
"classify_input": doc.get("classify_input"),
|
||||
})
|
||||
|
||||
def _handle_api_document_delete(self, parsed):
|
||||
|
||||
@@ -36,13 +36,13 @@ def delete(doc_id):
|
||||
return execute("DELETE FROM documents WHERE id = %s", (doc_id,))
|
||||
|
||||
|
||||
def set_classification(doc_id, doc_type, own_number, parent_number, doc_date, counterparty, classify_raw=None):
|
||||
"""Store LLM classification results + raw response."""
|
||||
def set_classification(doc_id, doc_type, own_number, parent_number, doc_date, counterparty, classify_raw=None, classify_input=None):
|
||||
"""Store LLM classification results + raw response + input text."""
|
||||
return execute(
|
||||
"""UPDATE documents SET doc_type=%s, own_number=%s, parent_number=%s,
|
||||
doc_date=%s, counterparty=%s, classify_status='classified', classify_raw=%s
|
||||
doc_date=%s, counterparty=%s, classify_status='classified', classify_raw=%s, classify_input=%s
|
||||
WHERE id=%s""",
|
||||
(doc_type, own_number, parent_number, doc_date, counterparty, classify_raw, doc_id),
|
||||
(doc_type, own_number, parent_number, doc_date, counterparty, classify_raw, classify_input, doc_id),
|
||||
)
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ def list_by_batch(batch_id):
|
||||
"""All documents in a batch with classification fields."""
|
||||
return query(
|
||||
"""SELECT id, filename, status, doc_type, own_number, parent_number,
|
||||
doc_date, counterparty, classify_status, error_message, classify_raw
|
||||
doc_date, counterparty, classify_status, error_message, classify_raw, classify_input
|
||||
FROM documents WHERE batch_id=%s ORDER BY created_at""",
|
||||
(batch_id,),
|
||||
)
|
||||
|
||||
@@ -82,6 +82,7 @@ def classify_batch(batch_id):
|
||||
result.get("doc_date"),
|
||||
result.get("counterparty"),
|
||||
classify_raw=raw,
|
||||
classify_input=text,
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user