v1.0.113: prompt_version in spec_events — provenance (who created what with which prompt)

This commit is contained in:
2026-06-23 07:08:23 +04:00
parent 534f90a529
commit b75b206bfe
4 changed files with 40 additions and 22 deletions
+6 -3
View File
@@ -101,12 +101,13 @@ def _build_spec_text(current_spec: list) -> str:
return "\n".join(lines)
def build_prompt(current_spec: list, doc_text: str) -> str:
def build_prompt(current_spec: list, doc_text: str) -> tuple:
"""
Формирует промпт для LLM.
1. Пробует получить активный промпт из БД (Lucee API).
2. При неудаче — fallback на хардкод.
Возвращает готовый текст промпта.
Возвращает (текст_промпта, prompt_id).
prompt_id — UUID версии промпта из БД, или "" если fallback.
"""
is_first = len(current_spec) == 0
role = "extract" if is_first else "diff"
@@ -114,11 +115,13 @@ def build_prompt(current_spec: list, doc_text: str) -> str:
db = _fetch_prompt(role)
if db:
template = db["body"]
prompt_id = db.get("id", "")
else:
template = FALLBACK_EXTRACT if is_first else FALLBACK_DIFF
prompt_id = ""
# Подстановка плейсхолдеров
result = template.replace("{doc_text}", doc_text)
result = result.replace("{spec_current}", _build_spec_text(current_spec))
return result
return result, prompt_id