Enhance Planning AI Context with Catalog Exercise Hints
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Successful in 1m15s
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Successful in 1m15s
- Introduced support for catalog exercise hints in various functions, including `_build_stage_ai_context`, `try_suggest_ai_stage_step`, and `build_gap_fill_goal_text`, improving the contextual information available for AI suggestions. - Added a new function `catalog_exercise_hints_block` to consolidate hints retrieval from the catalog context. - Updated the `PlanningIntentContext` to include catalog exercise hints, ensuring they are part of the API output. - Implemented tests to verify the inclusion of catalog exercise hints in goal text generation and rematch logic. - Incremented version numbers and updated changelog to reflect these enhancements.
This commit is contained in:
1 parent
35fe31774b
commit
3181cc126d
11 files changed
+166
-14
No files matched your search
@@ -19,6 +19,8 @@ from planning_exercise_form_context import (
|
||||
prior_path_steps_before_major,
|
||||
)
|
||||
from planning_exercise_semantics import PlanningSemanticBrief, brief_to_summary_dict
|
||||
from planning_catalog_context import ProgressionPlanningCatalogContext
|
||||
from planning_prompt_variables import catalog_exercise_hints_block
|
||||
|
||||
_logger = logging.getLogger("shinkan.planning_exercise_path_ai_fill")
|
||||
|
||||
@@ -54,6 +56,7 @@ def _build_stage_ai_context(
|
||||
step_after: Optional[Mapping[str, Any]] = None,
|
||||
prior_steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
start_situation: Optional[str] = None,
|
||||
catalog_exercise_hints: Optional[str] = None,
|
||||
) -> ExerciseFormAiPromptContext:
|
||||
"""KI-Kontext für unbesetzte Roadmap-Stufe (keine Brücke zwischen falschen Array-Indizes)."""
|
||||
gap = dict(spec.get("gap") or {})
|
||||
@@ -97,6 +100,9 @@ def _build_stage_ai_context(
|
||||
sketch = (spec.get("sketch") or "").strip()
|
||||
if sketch and sketch != learning_goal:
|
||||
goal_parts.extend(["", f"Kontext: {sketch}"])
|
||||
hints = (catalog_exercise_hints or "").strip()
|
||||
if hints:
|
||||
goal_parts.extend(["", "Katalog-Hinweise Übungsanlage:", hints])
|
||||
goal = "\n".join(goal_parts)
|
||||
|
||||
focus_hint = topic if brief.topic_type == "technique" else None
|
||||
@@ -118,6 +124,7 @@ def try_suggest_ai_stage_step(
|
||||
brief: PlanningSemanticBrief,
|
||||
spec: Mapping[str, Any],
|
||||
steps: Sequence[Mapping[str, Any]],
|
||||
catalog: Optional[ProgressionPlanningCatalogContext] = None,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""KI-Vorschlag für leere Roadmap-Stufe."""
|
||||
major_idx = spec.get("roadmap_major_step_index")
|
||||
@@ -136,6 +143,8 @@ def try_suggest_ai_stage_step(
|
||||
if not gap.get("learning_goal"):
|
||||
gap["learning_goal"] = spec.get("title_hint") or spec.get("sketch")
|
||||
|
||||
exercise_hints = catalog_exercise_hints_block(cur, catalog) if catalog else ""
|
||||
|
||||
ctx = _build_stage_ai_context(
|
||||
goal_query=goal_query,
|
||||
brief=brief,
|
||||
@@ -143,6 +152,7 @@ def try_suggest_ai_stage_step(
|
||||
step_before=step_before,
|
||||
step_after=step_after,
|
||||
prior_steps=prior_steps,
|
||||
catalog_exercise_hints=exercise_hints or None,
|
||||
)
|
||||
try:
|
||||
ai_payload = run_exercise_form_ai_suggestion(cur, ctx=ctx)
|
||||
@@ -189,6 +199,7 @@ def _build_gap_ai_context(
|
||||
gap: Mapping[str, Any],
|
||||
title_hint: Optional[str] = None,
|
||||
sketch_hint: Optional[str] = None,
|
||||
catalog_exercise_hints: Optional[str] = None,
|
||||
) -> ExerciseFormAiPromptContext:
|
||||
topic = (brief.primary_topic or "Technik").strip()
|
||||
phase = gap.get("expected_phase") or "vertiefung"
|
||||
@@ -206,6 +217,9 @@ def _build_gap_ai_context(
|
||||
]
|
||||
if sketch:
|
||||
goal_parts.extend(["", f"Hinweis: {sketch}"])
|
||||
hints = (catalog_exercise_hints or "").strip()
|
||||
if hints:
|
||||
goal_parts.extend(["", "Katalog-Hinweise Übungsanlage:", hints])
|
||||
goal = "\n".join(goal_parts)
|
||||
|
||||
focus_hint = topic if brief.topic_type == "technique" else None
|
||||
@@ -271,8 +285,10 @@ def try_suggest_ai_bridge_step(
|
||||
gap: Mapping[str, Any],
|
||||
title_hint: Optional[str] = None,
|
||||
sketch_hint: Optional[str] = None,
|
||||
catalog: Optional[ProgressionPlanningCatalogContext] = None,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Ruft exercise AI suggest auf — kein Speichern in DB."""
|
||||
exercise_hints = catalog_exercise_hints_block(cur, catalog) if catalog else ""
|
||||
ctx = _build_gap_ai_context(
|
||||
goal_query=goal_query,
|
||||
brief=brief,
|
||||
@@ -281,6 +297,7 @@ def try_suggest_ai_bridge_step(
|
||||
gap=gap,
|
||||
title_hint=title_hint,
|
||||
sketch_hint=sketch_hint,
|
||||
catalog_exercise_hints=exercise_hints or None,
|
||||
)
|
||||
g_plain = strip_html_to_plain(ctx.goal)
|
||||
if not g_plain.strip() and not (ctx.title or "").strip():
|
||||
@@ -478,6 +495,7 @@ def build_gap_fill_goal_text(
|
||||
step_a: Optional[Mapping[str, Any]] = None,
|
||||
step_b: Optional[Mapping[str, Any]] = None,
|
||||
roadmap_snapshot: Optional[Mapping[str, Any]] = None,
|
||||
catalog_exercise_hints: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Ausführlicher Zieltext für KI-Neuanlage aus Pfad-, Roadmap- und Stufen-Kontext."""
|
||||
topic = (brief.primary_topic or "Technik").strip()
|
||||
@@ -555,6 +573,9 @@ def build_gap_fill_goal_text(
|
||||
parts.append(f"Qualitätsprüfung: {spec['rationale']}")
|
||||
if spec.get("sketch"):
|
||||
parts.append(f"Skizze: {spec['sketch']}")
|
||||
hints = (catalog_exercise_hints or "").strip()
|
||||
if hints:
|
||||
parts.append(f"Katalog-Hinweise Übungsanlage:\n{hints}")
|
||||
parts.append(
|
||||
"Die Übung muss die Stufe didaktisch erfüllen: klare Voraussetzungen, messbares Stufenziel, "
|
||||
"Bezug zum Gesamtpfad — keine generische Kraftübung ohne Technikbezug. "
|
||||
@@ -571,6 +592,7 @@ def build_gap_fill_offer(
|
||||
brief: Optional[PlanningSemanticBrief] = None,
|
||||
proposal: Optional[Mapping[str, Any]] = None,
|
||||
roadmap_snapshot: Optional[Mapping[str, Any]] = None,
|
||||
catalog_exercise_hints: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
source = spec.get("source")
|
||||
idx = int(spec.get("insert_after_index") or 0)
|
||||
@@ -603,6 +625,7 @@ def build_gap_fill_offer(
|
||||
step_a=step_a,
|
||||
step_b=step_b,
|
||||
roadmap_snapshot=enriched_snapshot or None,
|
||||
catalog_exercise_hints=catalog_exercise_hints,
|
||||
)
|
||||
ctx_preview = enriched_snapshot or None
|
||||
offer: Dict[str, Any] = {
|
||||
@@ -642,6 +665,7 @@ def apply_gap_fill_after_qa(
|
||||
max_ai_proposals: int = 3,
|
||||
auto_insert_proposals: bool = False,
|
||||
roadmap_snapshot: Optional[Mapping[str, Any]] = None,
|
||||
catalog: Optional[ProgressionPlanningCatalogContext] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]], List[Dict[str, Any]]]:
|
||||
"""
|
||||
Erzeugt gap_fill_offers für die UI; optional KI-Vorschläge einfügen.
|
||||
@@ -653,6 +677,7 @@ def apply_gap_fill_after_qa(
|
||||
out = list(steps)
|
||||
proposals: List[Dict[str, Any]] = []
|
||||
offers: List[Dict[str, Any]] = []
|
||||
exercise_hints = catalog_exercise_hints_block(cur, catalog) if catalog else ""
|
||||
|
||||
for spec in specs:
|
||||
source = spec.get("source")
|
||||
@@ -666,6 +691,7 @@ def apply_gap_fill_after_qa(
|
||||
brief=brief,
|
||||
spec=spec,
|
||||
steps=out,
|
||||
catalog=catalog,
|
||||
)
|
||||
offer = build_gap_fill_offer(
|
||||
spec=spec,
|
||||
@@ -674,6 +700,7 @@ def apply_gap_fill_after_qa(
|
||||
brief=brief,
|
||||
proposal=proposal,
|
||||
roadmap_snapshot=roadmap_snapshot,
|
||||
catalog_exercise_hints=exercise_hints or None,
|
||||
)
|
||||
offers.append(offer)
|
||||
if proposal and auto_insert_proposals:
|
||||
@@ -700,6 +727,7 @@ def apply_gap_fill_after_qa(
|
||||
brief=brief,
|
||||
proposal=None,
|
||||
roadmap_snapshot=roadmap_snapshot,
|
||||
catalog_exercise_hints=exercise_hints or None,
|
||||
)
|
||||
offers.append(offer)
|
||||
continue
|
||||
@@ -719,6 +747,7 @@ def apply_gap_fill_after_qa(
|
||||
gap=gap,
|
||||
title_hint=str(spec.get("title_hint") or ""),
|
||||
sketch_hint=str(spec.get("sketch") or ""),
|
||||
catalog=catalog,
|
||||
)
|
||||
|
||||
offer = build_gap_fill_offer(
|
||||
@@ -728,6 +757,7 @@ def apply_gap_fill_after_qa(
|
||||
brief=brief,
|
||||
proposal=proposal,
|
||||
roadmap_snapshot=roadmap_snapshot,
|
||||
catalog_exercise_hints=exercise_hints or None,
|
||||
)
|
||||
offers.append(offer)
|
||||
|
||||
|
||||
Reference in new issue
Block a user