feat(test): action 'extract' — извлечение строк спецификации через LLM
This commit is contained in:
@@ -17,6 +17,7 @@ from psycopg2 import sql as psysql
|
||||
from flask import Blueprint, jsonify, request
|
||||
import db
|
||||
import llm_client
|
||||
import extractor
|
||||
|
||||
test_bp = Blueprint("test", __name__)
|
||||
|
||||
@@ -41,6 +42,7 @@ def test():
|
||||
"POST /test tables — список таблиц",
|
||||
"POST /test exec {...} — INSERT/UPDATE/DDL (без fetch)",
|
||||
"POST /test llm {...} — тест LLM (промпт → ответ)",
|
||||
"POST /test extract {...} — извлечь строки из parsed_text",
|
||||
"POST /test sql {...} — SELECT (с fetch)",
|
||||
],
|
||||
})
|
||||
@@ -116,6 +118,29 @@ def test():
|
||||
return jsonify(result), 500
|
||||
return jsonify(result)
|
||||
|
||||
if action == "extract":
|
||||
# Извлечь строки спецификации из текста документа
|
||||
doc_id = data.get("document_id")
|
||||
if doc_id:
|
||||
# Взять текст из БД
|
||||
doc, err = db.query_one(
|
||||
"SELECT parsed_text FROM documents WHERE id = %s AND status = 'parsed'",
|
||||
(doc_id,),
|
||||
)
|
||||
if err or not doc:
|
||||
return jsonify({"error": f"document not found: {err}"}), 404
|
||||
parsed_text = doc["parsed_text"]
|
||||
else:
|
||||
parsed_text = data.get("text", "")
|
||||
|
||||
if not parsed_text:
|
||||
return jsonify({"error": "no parsed_text"}), 400
|
||||
|
||||
result = extractor.extract(parsed_text)
|
||||
if "error" in result:
|
||||
return jsonify(result), 500
|
||||
return jsonify(result)
|
||||
|
||||
if action == "debug":
|
||||
# Показать переменные окружения (с маскировкой ключей)
|
||||
import os as _os
|
||||
|
||||
Reference in New Issue
Block a user