v1.0.176: prompts — seed per-role + _serialize non-mutating
This commit is contained in:
@@ -3,8 +3,9 @@ from .connection import query, execute, execute_returning
|
||||
|
||||
|
||||
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"):
|
||||
row = dict(row)
|
||||
row["created_at"] = str(row["created_at"])
|
||||
return row
|
||||
|
||||
@@ -24,10 +25,10 @@ def get(prompt_id):
|
||||
|
||||
def seed_defaults():
|
||||
"""Auto-seed default prompts if table is empty."""
|
||||
count = query("SELECT COUNT(*) as cnt FROM prompts")
|
||||
if count[0]["cnt"] > 0:
|
||||
return
|
||||
# Check each role separately — don't skip if one is missing
|
||||
existing_roles = set(r["role"] for r in query("SELECT DISTINCT role FROM prompts"))
|
||||
|
||||
if "extract" not in existing_roles:
|
||||
extract_body = (
|
||||
"Ты — анализатор договоров облачного провайдера.\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)",
|
||||
("extract", "default-v1", extract_body, True, "Авто-создан из llm_prompt.py _build_initial"),
|
||||
)
|
||||
|
||||
if "diff" not in existing_roles:
|
||||
diff_body = (
|
||||
"Ты — анализатор допсоглашений к договорам облачного провайдера.\n\n"
|
||||
"У тебя есть текущая спецификация услуг и текст нового допсоглашения (ДС).\n"
|
||||
|
||||
Reference in New Issue
Block a user