Enhance Planning Exercise Path AI and UI Integration
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 40s
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 1m13s
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 40s
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 1m13s
- Updated the AI gap filling logic to include structured offers for unfilled gaps, improving the user experience in the Exercise Progression Path Builder. - Introduced new functions for detecting off-topic steps and parsing LLM-suggested exercises, enhancing the contextual relevance of exercise suggestions. - Enhanced the frontend components to support new AI proposal features, including quick creation modals for newly suggested exercises. - Incremented version to 0.8.190 and updated changelog to reflect these improvements in planning AI functionality.
This commit is contained in:
1 parent
8d1dd59c3c
commit
3450a9296a
7 files changed
+915
-88
No files matched your search
@@ -19,6 +19,7 @@ from openrouter_chat import (
|
||||
from planning_exercise_semantics import (
|
||||
PlanningSemanticBrief,
|
||||
brief_to_summary_dict,
|
||||
exercise_passes_path_semantic_gate,
|
||||
score_exercise_semantic_relevance,
|
||||
step_phase_for_index,
|
||||
)
|
||||
@@ -230,6 +231,18 @@ def insert_bridge_exercises(
|
||||
i += 1
|
||||
continue
|
||||
|
||||
bridge_sem = float(bridge_hit.get("semantic_score") or 0.0)
|
||||
if brief.semantic_strength >= 0.55 and not exercise_passes_path_semantic_gate(
|
||||
semantic_score=bridge_sem,
|
||||
title=str(bridge_hit.get("title") or ""),
|
||||
summary=str(bridge_hit.get("summary") or ""),
|
||||
brief=brief,
|
||||
strict=True,
|
||||
):
|
||||
unfilled.append({**gap, "weak_bridge_rejected": True, "bridge_title": bridge_hit.get("title")})
|
||||
i += 1
|
||||
continue
|
||||
|
||||
bridge_step = {
|
||||
"exercise_id": int(bridge_hit["id"]),
|
||||
"variant_id": bridge_hit.get("suggested_variant_id"),
|
||||
@@ -351,16 +364,133 @@ def apply_llm_path_reorder(
|
||||
return [steps[i] for i in indices], True, notes
|
||||
|
||||
|
||||
_OFF_TOPIC_SEMANTIC_MAX = 0.10
|
||||
|
||||
|
||||
def detect_off_topic_steps(
|
||||
cur,
|
||||
steps: Sequence[Mapping[str, Any]],
|
||||
*,
|
||||
brief: PlanningSemanticBrief,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Schritte ohne Bezug zum Pfad-Thema (z. B. reine Kraftübungen bei Mae Geri)."""
|
||||
if brief.semantic_strength < 0.55 or len(steps) < 2:
|
||||
return []
|
||||
|
||||
off_topic: List[Dict[str, Any]] = []
|
||||
total = len(steps)
|
||||
for idx, step in enumerate(steps):
|
||||
if step.get("is_ai_proposal") or step.get("exercise_id") is None:
|
||||
continue
|
||||
bundle = _load_exercise_text_bundle(cur, int(step["exercise_id"]))
|
||||
phase = step_phase_for_index(brief, idx, total)
|
||||
sem, sem_reasons = score_exercise_semantic_relevance(
|
||||
title=bundle["title"],
|
||||
summary=bundle["summary"],
|
||||
goal=bundle["goal"],
|
||||
variant_names=bundle["variant_names"],
|
||||
brief=brief,
|
||||
step_phase=phase,
|
||||
)
|
||||
if exercise_passes_path_semantic_gate(
|
||||
semantic_score=sem,
|
||||
title=bundle["title"],
|
||||
summary=bundle["summary"],
|
||||
goal=bundle["goal"],
|
||||
brief=brief,
|
||||
strict=True,
|
||||
):
|
||||
continue
|
||||
if sem > _OFF_TOPIC_SEMANTIC_MAX:
|
||||
continue
|
||||
off_topic.append(
|
||||
{
|
||||
"step_index": idx,
|
||||
"exercise_id": int(step["exercise_id"]),
|
||||
"title": step.get("title") or bundle["title"],
|
||||
"semantic_score": round(sem, 4),
|
||||
"expected_phase": phase,
|
||||
"issue": "off_topic",
|
||||
"reasons": sem_reasons[:3],
|
||||
}
|
||||
)
|
||||
return off_topic
|
||||
|
||||
|
||||
def parse_llm_suggested_new_exercises(
|
||||
llm_qa: Optional[Mapping[str, Any]],
|
||||
*,
|
||||
brief: PlanningSemanticBrief,
|
||||
step_count: int,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Strukturierte Neuanlage-Vorschläge aus LLM-Pfad-QS."""
|
||||
if not llm_qa:
|
||||
return []
|
||||
raw = llm_qa.get("suggested_new_exercises")
|
||||
if not isinstance(raw, list):
|
||||
return []
|
||||
|
||||
topic = (brief.primary_topic or "Technik").strip()
|
||||
out: List[Dict[str, Any]] = []
|
||||
for item in raw[:5]:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
title_hint = str(item.get("title_hint") or item.get("title") or "").strip()
|
||||
if len(title_hint) < 3:
|
||||
title_hint = f"{topic} — Zwischenschritt"
|
||||
sketch = str(item.get("sketch") or item.get("goal_hint") or item.get("rationale") or "").strip()
|
||||
phase = str(item.get("phase") or item.get("expected_phase") or "vertiefung").strip()
|
||||
rationale = str(item.get("rationale") or "").strip()
|
||||
insert_after = item.get("insert_after_step_index")
|
||||
if insert_after is None:
|
||||
insert_after = item.get("insert_after_index")
|
||||
try:
|
||||
insert_idx = int(insert_after) if insert_after is not None else max(0, step_count // 2 - 1)
|
||||
except (TypeError, ValueError):
|
||||
insert_idx = max(0, step_count // 2 - 1)
|
||||
insert_idx = max(0, min(step_count - 2, insert_idx))
|
||||
out.append(
|
||||
{
|
||||
"source": "llm_suggested",
|
||||
"insert_after_index": insert_idx,
|
||||
"title_hint": title_hint[:280],
|
||||
"sketch": sketch[:1200],
|
||||
"phase": phase,
|
||||
"rationale": rationale[:500],
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
def find_step_pair_index(
|
||||
steps: Sequence[Mapping[str, Any]],
|
||||
from_exercise_id: int,
|
||||
to_exercise_id: int,
|
||||
) -> Optional[int]:
|
||||
for i in range(len(steps) - 1):
|
||||
a = steps[i]
|
||||
b = steps[i + 1]
|
||||
if a.get("exercise_id") is None or b.get("exercise_id") is None:
|
||||
continue
|
||||
if int(a["exercise_id"]) == int(from_exercise_id) and int(b["exercise_id"]) == int(to_exercise_id):
|
||||
return i
|
||||
return None
|
||||
|
||||
|
||||
def build_path_qa_summary(
|
||||
*,
|
||||
gaps: Sequence[Mapping[str, Any]],
|
||||
bridge_inserts: Sequence[Mapping[str, Any]],
|
||||
ai_proposals: Sequence[Mapping[str, Any]],
|
||||
gap_fill_offers: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
off_topic_steps: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||
llm_qa: Optional[Mapping[str, Any]],
|
||||
llm_applied: bool,
|
||||
reorder_applied: bool = False,
|
||||
reorder_notes: Optional[Sequence[str]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
offers = list(gap_fill_offers or [])
|
||||
off_topic = list(off_topic_steps or [])
|
||||
summary: Dict[str, Any] = {
|
||||
"gap_count": len(gaps),
|
||||
"large_gaps": list(gaps),
|
||||
@@ -368,6 +498,10 @@ def build_path_qa_summary(
|
||||
"bridge_inserts": list(bridge_inserts),
|
||||
"ai_proposal_count": len(ai_proposals),
|
||||
"ai_proposals": list(ai_proposals),
|
||||
"gap_fill_offer_count": len(offers),
|
||||
"gap_fill_offers": offers,
|
||||
"off_topic_count": len(off_topic),
|
||||
"off_topic_steps": off_topic,
|
||||
"llm_qa_applied": llm_applied,
|
||||
"reorder_applied": reorder_applied,
|
||||
"reorder_notes": list(reorder_notes or []),
|
||||
@@ -379,20 +513,29 @@ def build_path_qa_summary(
|
||||
summary["sequence_notes"] = list(llm_qa.get("sequence_notes") or [])
|
||||
summary["topic_coverage"] = llm_qa.get("topic_coverage")
|
||||
summary["recommendations"] = list(llm_qa.get("recommendations") or [])
|
||||
summary["suggested_new_exercises"] = list(llm_qa.get("suggested_new_exercises") or [])
|
||||
else:
|
||||
summary["overall_ok"] = len(gaps) == 0
|
||||
summary["overall_ok"] = len(gaps) == 0 and len(off_topic) == 0
|
||||
summary["issues"] = [
|
||||
f"Lücke zwischen „{g.get('from_title')}“ und „{g.get('to_title')}“ (Score {g.get('gap_score')})"
|
||||
for g in gaps
|
||||
] if gaps else []
|
||||
if off_topic:
|
||||
summary["issues"] = list(summary["issues"]) + [
|
||||
f"Schritt „{o.get('title')}“ passt nicht zum Pfad-Thema"
|
||||
for o in off_topic
|
||||
]
|
||||
return summary
|
||||
|
||||
|
||||
__all__ = [
|
||||
"apply_llm_path_reorder",
|
||||
"build_path_qa_summary",
|
||||
"detect_off_topic_steps",
|
||||
"detect_path_gaps",
|
||||
"find_step_pair_index",
|
||||
"insert_bridge_exercises",
|
||||
"measure_step_transition_gap",
|
||||
"parse_llm_suggested_new_exercises",
|
||||
"try_llm_qa_progression_path",
|
||||
]
|
||||
Reference in new issue
Block a user