All checks were successful
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.
87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
"""
|
|
Gemeinsame Pydantic-Modelle fuer Uebungs-KI-Kontext (Formularfelder → Prompt-Platzhalter).
|
|
|
|
Keine Imports aus exercise_ai — vermeidet Zirkelimporte mit ai_prompt_job / exercise_ai.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import List, Optional, Sequence, Tuple
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ExerciseFormAiFocusRow(BaseModel):
|
|
"""Fokusbereich fuer Skill-Retrieval (ai_skill_retrieval_profiles)."""
|
|
|
|
focus_area_id: int = Field(..., ge=1)
|
|
is_primary: Optional[bool] = False
|
|
|
|
|
|
class ExerciseFormAiPromptContext(BaseModel):
|
|
"""
|
|
Inhaltliche Eingabe fuer Uebungs-Prompts (Kurzfassung / Skill-Vorschlaege).
|
|
|
|
Wird genutzt von Admin-Prompt-Vorschau und POST /exercises/ai/suggest (via Mapping).
|
|
"""
|
|
|
|
title: Optional[str] = ""
|
|
goal: Optional[str] = None
|
|
execution: Optional[str] = None
|
|
focus_hint: Optional[str] = None
|
|
focus_areas_context: Optional[List[ExerciseFormAiFocusRow]] = None
|
|
|
|
def focus_area_tuples(self) -> Optional[List[Tuple[int, bool]]]:
|
|
if not self.focus_areas_context:
|
|
return None
|
|
return [(int(x.focus_area_id), bool(x.is_primary)) for x in self.focus_areas_context]
|
|
|
|
@classmethod
|
|
def from_api_suggest(
|
|
cls,
|
|
*,
|
|
title: Optional[str] = None,
|
|
goal: Optional[str] = None,
|
|
execution: Optional[str] = None,
|
|
focus_area_hint: Optional[str] = None,
|
|
focus_areas_context: Optional[Sequence[ExerciseFormAiFocusRow]] = None,
|
|
) -> ExerciseFormAiPromptContext:
|
|
"""Mappt Felder aus POST /exercises/ai/suggest (focus_area_hint → focus_hint)."""
|
|
hint = (focus_area_hint or "").strip() or None
|
|
return cls(
|
|
title=(title or "").strip(),
|
|
goal=goal,
|
|
execution=execution,
|
|
focus_hint=hint,
|
|
focus_areas_context=list(focus_areas_context) if focus_areas_context else None,
|
|
)
|
|
|
|
@classmethod
|
|
def from_focus_tuples(
|
|
cls,
|
|
*,
|
|
title: str = "",
|
|
goal: Optional[str] = None,
|
|
execution: Optional[str] = None,
|
|
focus_hint: Optional[str] = None,
|
|
focus_tuples: Optional[Sequence[Tuple[int, bool]]] = None,
|
|
) -> ExerciseFormAiPromptContext:
|
|
rows = None
|
|
if focus_tuples:
|
|
rows = [
|
|
ExerciseFormAiFocusRow(focus_area_id=int(fid), is_primary=bool(prim))
|
|
for fid, prim in focus_tuples
|
|
]
|
|
return cls(
|
|
title=(title or "").strip(),
|
|
goal=goal,
|
|
execution=execution,
|
|
focus_hint=(focus_hint or "").strip() or None,
|
|
focus_areas_context=rows,
|
|
)
|
|
|
|
|
|
__all__ = [
|
|
"ExerciseFormAiFocusRow",
|
|
"ExerciseFormAiPromptContext",
|
|
]
|