v1.0.176: prompts — seed per-role + _serialize non-mutating

This commit is contained in:
2026-06-24 18:07:02 +04:00
parent 0e0939bb32
commit a36c8fa2bf
+7 -4
View File
@@ -3,8 +3,9 @@ from .connection import query, execute, execute_returning
def _serialize(row): def _serialize(row):
"""Convert datetime fields to strings for JSON serialization.""" """Convert datetime fields to strings for JSON serialization (non-mutating)."""
if row and row.get("created_at"): if row and row.get("created_at"):
row = dict(row)
row["created_at"] = str(row["created_at"]) row["created_at"] = str(row["created_at"])
return row return row
@@ -24,10 +25,10 @@ def get(prompt_id):
def seed_defaults(): def seed_defaults():
"""Auto-seed default prompts if table is empty.""" """Auto-seed default prompts if table is empty."""
count = query("SELECT COUNT(*) as cnt FROM prompts") # Check each role separately — don't skip if one is missing
if count[0]["cnt"] > 0: existing_roles = set(r["role"] for r in query("SELECT DISTINCT role FROM prompts"))
return
if "extract" not in existing_roles:
extract_body = ( extract_body = (
"Ты — анализатор договоров облачного провайдера.\n\n" "Ты — анализатор договоров облачного провайдера.\n\n"
"Ниже текст спецификации услуг из ПЕРВОГО документа (базовый договор).\n" "Ниже текст спецификации услуг из ПЕРВОГО документа (базовый договор).\n"
@@ -48,6 +49,8 @@ def seed_defaults():
"INSERT INTO prompts (role, name, body, is_active, notes) VALUES (%s, %s, %s, %s, %s)", "INSERT INTO prompts (role, name, body, is_active, notes) VALUES (%s, %s, %s, %s, %s)",
("extract", "default-v1", extract_body, True, "Авто-создан из llm_prompt.py _build_initial"), ("extract", "default-v1", extract_body, True, "Авто-создан из llm_prompt.py _build_initial"),
) )
if "diff" not in existing_roles:
diff_body = ( diff_body = (
"Ты — анализатор допсоглашений к договорам облачного провайдера.\n\n" "Ты — анализатор допсоглашений к договорам облачного провайдера.\n\n"
"У тебя есть текущая спецификация услуг и текст нового допсоглашения (ДС).\n" "У тебя есть текущая спецификация услуг и текст нового допсоглашения (ДС).\n"