Implement Planning Prompt Enhancements and LLM Usage Tracking
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 49s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m26s
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 49s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m26s
- Added new fields for goal query, user notes, max steps, and search query in the AiPromptPreviewBody to support planning prompts. - Integrated planning prompt handling in the preview_ai_prompt function, allowing for distinct processing of planning and exercise prompts. - Introduced LLM usage tracking in openrouter_chat_completion and planning_exercise_suggest functions to monitor AI call metrics. - Updated frontend components to accommodate new input fields for planning prompts, enhancing user experience and functionality.
This commit is contained in:
1 parent
0b203489f7
commit
9cee862c32
9 files changed
+679
-66
No files matched your search
@@ -14,6 +14,11 @@ from auth import require_auth
|
||||
from club_tenancy import is_superadmin
|
||||
from ai_prompt_context import ExerciseFormAiPromptContext
|
||||
from ai_prompt_job import resolve_exercise_form_variables
|
||||
from ai_prompt_planning_preview import (
|
||||
PlanningPromptPreviewInput,
|
||||
is_planning_prompt_slug,
|
||||
resolve_planning_prompt_preview_variables,
|
||||
)
|
||||
from ai_prompt_runtime import render_ai_prompt_template_for_row
|
||||
from db import get_cursor, get_db, r2d
|
||||
from prompt_resolver import exercise_placeholder_catalog
|
||||
@@ -62,7 +67,12 @@ class AiPromptUpdateBody(BaseModel):
|
||||
|
||||
|
||||
class AiPromptPreviewBody(ExerciseFormAiPromptContext):
|
||||
"""Preview-POST: gleiche Felder wie ExerciseFormAiPromptContext (focus_hint, nicht focus_area_hint)."""
|
||||
"""Preview-POST: Übungs-KI und Planungs-Prompts."""
|
||||
|
||||
goal_query: Optional[str] = Field(default=None, max_length=2000)
|
||||
user_notes: Optional[str] = Field(default=None, max_length=2000)
|
||||
max_steps: Optional[int] = Field(default=None, ge=2, le=10)
|
||||
search_query: Optional[str] = Field(default=None, max_length=2000)
|
||||
|
||||
|
||||
@router.get("/api/admin/ai-prompts/catalog/placeholders")
|
||||
@@ -223,6 +233,17 @@ def preview_ai_prompt(prompt_id: int, body: AiPromptPreviewBody, session: dict =
|
||||
vars_map = resolve_exercise_form_variables(cur, slug, body)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
elif is_planning_prompt_slug(slug):
|
||||
planning_in = PlanningPromptPreviewInput(
|
||||
goal_query=(body.goal_query or "Mae Geri vom Grundschritt bis zur Kumite-Nähe").strip(),
|
||||
user_notes=(body.user_notes or "").strip(),
|
||||
max_steps=body.max_steps if body.max_steps is not None else 5,
|
||||
search_query=(body.search_query or body.goal_query or "").strip() or None,
|
||||
)
|
||||
try:
|
||||
vars_map = resolve_planning_prompt_preview_variables(cur, slug, planning_in)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
elif slug == "pipeline":
|
||||
vars_map = {}
|
||||
warn = "Pipeline-Slug: keine Kontextsubstitution fuer Vorschau."
|
||||
|
||||
@@ -7,6 +7,7 @@ from db import get_db, get_cursor
|
||||
from tenant_context import TenantContext, get_tenant_context
|
||||
from planning_exercise_suggest import PlanningExerciseSuggestRequest, suggest_planning_exercises
|
||||
from planning_exercise_path_builder import ProgressionPathSuggestRequest, suggest_progression_path
|
||||
from planning_llm_usage import planning_llm_call_meter
|
||||
from account_lifecycle import assert_min_account_state
|
||||
from capabilities import probe_capability
|
||||
from club_features import (
|
||||
@@ -46,19 +47,25 @@ def post_planning_exercise_suggest(
|
||||
)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
result = suggest_planning_exercises(cur, tenant=tenant, body=body)
|
||||
if uses_ai:
|
||||
with planning_llm_call_meter() as llm_meter:
|
||||
result = suggest_planning_exercises(cur, tenant=tenant, body=body)
|
||||
if uses_ai and llm_meter.count > 0:
|
||||
usage = consume_club_feature_with_usage(
|
||||
feature_id="ai_calls",
|
||||
club_id=club_id,
|
||||
profile_id=tenant.profile_id,
|
||||
portal_role=tenant.global_role,
|
||||
action="planning_suggest",
|
||||
amount=llm_meter.count,
|
||||
cur=cur,
|
||||
tenant=tenant,
|
||||
conn=conn,
|
||||
)
|
||||
result = merge_feature_usage_into_response(result, usage)
|
||||
if isinstance(result, dict):
|
||||
result["llm_call_count"] = llm_meter.count
|
||||
elif uses_ai and isinstance(result, dict):
|
||||
result["llm_call_count"] = 0
|
||||
return result
|
||||
|
||||
|
||||
@@ -97,17 +104,23 @@ def post_progression_path_suggest(
|
||||
)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
result = suggest_progression_path(cur, tenant=tenant, body=body)
|
||||
if uses_ai:
|
||||
with planning_llm_call_meter() as llm_meter:
|
||||
result = suggest_progression_path(cur, tenant=tenant, body=body)
|
||||
if uses_ai and llm_meter.count > 0:
|
||||
usage = consume_club_feature_with_usage(
|
||||
feature_id="ai_calls",
|
||||
club_id=club_id,
|
||||
profile_id=tenant.profile_id,
|
||||
portal_role=tenant.global_role,
|
||||
action="progression_path_suggest",
|
||||
amount=llm_meter.count,
|
||||
cur=cur,
|
||||
tenant=tenant,
|
||||
conn=conn,
|
||||
)
|
||||
result = merge_feature_usage_into_response(result, usage)
|
||||
if isinstance(result, dict):
|
||||
result["llm_call_count"] = llm_meter.count
|
||||
elif uses_ai and isinstance(result, dict):
|
||||
result["llm_call_count"] = 0
|
||||
return result
|
||||
Reference in new issue
Block a user