Implement ExerciseFormAiPromptContext and Refactor AI Prompt Job Functionality
Deploy Development / deploy (push) Successful in 40s
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 34s
Test Suite / playwright-tests (push) Successful in 1m23s
Deploy Development / deploy (push) Successful in 40s
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 34s
Test Suite / playwright-tests (push) Successful in 1m23s
- Introduced `ExerciseFormAiPromptContext` for unified handling of prompt-related data, enhancing the admin preview and exercise API. - Added `run_exercise_form_ai_suggestion` function to streamline AI suggestion processing, integrating with the OpenRouter. - Updated various modules to utilize the new context model, improving code clarity and reducing redundancy. - Incremented application version to 0.8.162 and updated changelog to reflect these changes, including migration details and new functionality.
This commit is contained in:
1 parent
93b8d09d05
commit
5331eab39c
8 files changed
+168
-85
No files matched your search
@@ -35,7 +35,8 @@ from tenant_context import TenantContext, get_tenant_context, get_tenant_context
|
||||
from media_storage import get_effective_media_root, library_storage_key, path_under_media_root
|
||||
from media_rights import assert_rights_for_exercise_link, validate_rights_declaration, write_rights_declaration, update_rights_quick_fields
|
||||
from media_legal_hold import assert_not_under_legal_hold
|
||||
from exercise_ai import run_exercise_ai_suggestion
|
||||
from ai_prompt_context import ExerciseFormAiFocusRow, ExerciseFormAiPromptContext
|
||||
from ai_prompt_job import run_exercise_form_ai_suggestion
|
||||
|
||||
from exercise_rich_text import (
|
||||
RICH_HTML_EXERCISE_FIELDS,
|
||||
@@ -358,11 +359,8 @@ class ExerciseMediaFromAsset(BaseModel):
|
||||
media_type: Optional[str] = None
|
||||
|
||||
|
||||
class ExerciseAiFocusCtx(BaseModel):
|
||||
"""Fokusbereich fuer Skill-Kataloggewichte (Migration 068 ai_skill_retrieval_profiles)."""
|
||||
|
||||
focus_area_id: int = Field(..., ge=1)
|
||||
is_primary: Optional[bool] = False
|
||||
class ExerciseAiFocusCtx(ExerciseFormAiFocusRow):
|
||||
"""Alias fuer OpenAPI — identisch zu ExerciseFormAiFocusRow."""
|
||||
|
||||
|
||||
class ExerciseAiSuggestBody(BaseModel):
|
||||
@@ -370,7 +368,7 @@ class ExerciseAiSuggestBody(BaseModel):
|
||||
goal: Optional[str] = Field(None, max_length=64000)
|
||||
execution: Optional[str] = Field(None, max_length=128000)
|
||||
focus_area_hint: Optional[str] = Field(None, max_length=1200)
|
||||
focus_areas_context: Optional[list[ExerciseAiFocusCtx]] = Field(
|
||||
focus_areas_context: Optional[list[ExerciseFormAiFocusRow]] = Field(
|
||||
None,
|
||||
description="Optionale Reihenfolge Primär zuerst; steuert Katalogpriorisierung",
|
||||
)
|
||||
@@ -383,6 +381,15 @@ class ExerciseAiSuggestBody(BaseModel):
|
||||
raise ValueError("Mindestens include_summary oder include_skills aktivieren.")
|
||||
return self
|
||||
|
||||
def to_form_context(self) -> ExerciseFormAiPromptContext:
|
||||
return ExerciseFormAiPromptContext.from_api_suggest(
|
||||
title=self.title,
|
||||
goal=self.goal,
|
||||
execution=self.execution,
|
||||
focus_area_hint=self.focus_area_hint,
|
||||
focus_areas_context=self.focus_areas_context,
|
||||
)
|
||||
|
||||
|
||||
class ExerciseAiRegenerateBody(BaseModel):
|
||||
"""Welche Artefakte neu angefragt werden sollen."""
|
||||
@@ -2306,17 +2313,9 @@ def exercise_ai_suggest_endpoint(
|
||||
_ = tenant.profile_id
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
fctx = None
|
||||
if body.focus_areas_context:
|
||||
fctx = [(x.focus_area_id, bool(x.is_primary)) for x in body.focus_areas_context]
|
||||
|
||||
payload = run_exercise_ai_suggestion(
|
||||
payload = run_exercise_form_ai_suggestion(
|
||||
cur,
|
||||
title=(body.title or "").strip(),
|
||||
goal=body.goal,
|
||||
execution=body.execution,
|
||||
focus_area_hint=(body.focus_area_hint or "").strip() or None,
|
||||
focus_areas_context=fctx,
|
||||
body.to_form_context(),
|
||||
want_summary=body.include_summary,
|
||||
want_skills=body.include_skills,
|
||||
)
|
||||
@@ -2344,13 +2343,16 @@ def exercise_ai_regenerate_endpoint(
|
||||
focus = _focus_area_hint_from_detail(exercise)
|
||||
fctx = _focus_areas_ai_ctx_from_detail(exercise)
|
||||
|
||||
payload = run_exercise_ai_suggestion(
|
||||
cur,
|
||||
ctx = ExerciseFormAiPromptContext.from_focus_tuples(
|
||||
title=str(exercise.get("title") or "").strip(),
|
||||
goal=exercise.get("goal"),
|
||||
execution=exercise.get("execution"),
|
||||
focus_area_hint=focus or None,
|
||||
focus_areas_context=fctx or None,
|
||||
focus_hint=focus or None,
|
||||
focus_tuples=fctx or None,
|
||||
)
|
||||
payload = run_exercise_form_ai_suggestion(
|
||||
cur,
|
||||
ctx,
|
||||
want_summary=want_summary,
|
||||
want_skills=want_skills,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user