Refactor AI Prompt System and Enhance Functionality
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 39s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m18s

- Introduced `load_and_render_ai_prompt` and `render_ai_prompt_template_for_row` in `ai_prompt_runtime` to streamline prompt loading and rendering processes.
- Added `AiPromptUnavailableError` for better error handling when prompts are inactive or missing.
- Created `ai_prompt_job` module with `ExerciseFormAiPromptContext` and `resolve_exercise_form_variables` to support admin preview functionality.
- Updated documentation and target architecture to reflect changes in the AI prompt system.
- Incremented application version to 0.8.160 and updated changelog accordingly.
This commit is contained in:
Lars committed 2026-05-22 12:19:52 +02:00
1 parent e22266a18c
commit 0551bb3d80
7 files changed
+146 -49

No files matched your search

+15 -13
View File
@@ -18,8 +18,7 @@ from fastapi import HTTPException
from openrouter_chat import OpenRouterError, normalize_openrouter_env, openrouter_chat_completion
from ai_prompt_runtime import load_ai_prompt_row
from prompt_resolver import render_mustache_template
from ai_prompt_runtime import AiPromptUnavailableError, load_and_render_ai_prompt
_LOGGER = logging.getLogger("shinkan.exercise_ai")
@@ -715,9 +714,6 @@ def run_exercise_ai_suggestion(
)
if want_summary:
prow = load_ai_prompt_row(cur, "exercise_summary")
if not prow:
raise HTTPException(status_code=503, detail="Prompt exercise_summary nicht aktiv oder fehlt in DB.")
try:
ctx = build_exercise_placeholder_variables(
cur,
@@ -730,7 +726,13 @@ def run_exercise_ai_suggestion(
)
except ValueError as e:
raise HTTPException(status_code=500, detail=str(e)) from e
rendered = render_mustache_template(str(prow["template"]), ctx)
try:
prow, rendered = load_and_render_ai_prompt(cur, "exercise_summary", ctx)
except AiPromptUnavailableError:
raise HTTPException(
status_code=503,
detail="Prompt exercise_summary nicht aktiv oder fehlt in DB.",
) from None
prompt = rendered.text
if _ai_debug_on():
_LOGGER.warning(
@@ -755,12 +757,6 @@ def run_exercise_ai_suggestion(
result["summary"] = {"text": text, "ai_generated": True, "model": model}
if want_skills:
srow = load_ai_prompt_row(cur, "exercise_skill_suggestions")
if not srow:
raise HTTPException(
status_code=503,
detail="Prompt exercise_skill_suggestions nicht aktiv oder fehlt in DB.",
)
try:
ctx = build_exercise_placeholder_variables(
cur,
@@ -773,7 +769,13 @@ def run_exercise_ai_suggestion(
)
except ValueError as e:
raise HTTPException(status_code=500, detail=str(e)) from e
rendered = render_mustache_template(str(srow["template"]), ctx)
try:
srow, rendered = load_and_render_ai_prompt(cur, "exercise_skill_suggestions", ctx)
except AiPromptUnavailableError:
raise HTTPException(
status_code=503,
detail="Prompt exercise_skill_suggestions nicht aktiv oder fehlt in DB.",
) from None
prompt = rendered.text
if _ai_debug_on():
_LOGGER.warning(