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

- 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:
Lars committed 2026-06-15 07:50:49 +02:00
1 parent 0b203489f7
commit 9cee862c32
9 files changed
+679 -66

No files matched your search

@@ -39,7 +39,6 @@ import {
compareDiffsForDialog,
dedupeGapOffersBySlot,
draftHasLibrarySlotAssignments,
draftRetrievalBoostExerciseIds,
EMPTY_PLANNING_CATALOG_CONTEXT,
filterGapOffersForUnfilledSlots,
hydrateProgressionGraphDraft,
@@ -478,28 +477,6 @@ export default function ProgressionGraphEditor({ graphId, embedded = false, onSa
}
}
const buildMatchRequestBase = (synced) => {
const override = majorStepsToOverridePayload(synced.slots)
return {
query: (synced.goalQuery || '').trim(),
max_steps: synced.slots.length,
include_llm_intent: true,
include_path_qa: true,
include_llm_path_qa: true,
include_path_reorder: false,
include_ai_gap_fill: true,
include_roadmap_preview: true,
include_llm_roadmap: false,
roadmap_first: true,
roadmap_override: override,
slot_assignments: slotsToSlotAssignments(synced),
retrieval_boost_exercise_ids: draftRetrievalBoostExerciseIds(synced),
progression_graph_id: Number(graphId),
...roadmapStructuredPayload(synced.startSituation, synced.targetState, synced.roadmapNotes),
...catalogApiPayload,
}
}
const runMatchCompareFlow = async (synced, { source = 'match' } = {}) => {
setMatchNotice('Schritt 1/2: Pfad bewerten (wie „Graph bewerten“)…')
const baselineRes = await fetchPathEvaluate(synced)
+116 -38
View File
@@ -31,8 +31,22 @@ export default function AdminAiPromptsPage() {
const [pvExec, setPvExec] = useState('<p>Ablauf hier</p>')
const [pvHint, setPvHint] = useState('')
const [pvFocusId, setPvFocusId] = useState('')
const [pvGoalQuery, setPvGoalQuery] = useState(
'Mae Geri vom Grundschritt bis zur kontrollierten Kumite-Nähe'
)
const [pvUserNotes, setPvUserNotes] = useState('Fokus Breitensport, ohne Wettkampfdruck.')
const [pvMaxSteps, setPvMaxSteps] = useState('5')
const [pvSearchQuery, setPvSearchQuery] = useState('')
const [pvPreview, setPvPreview] = useState(null)
const selectedSlug = (detail?.slug || '').trim().toLowerCase()
const isExercisePreviewSlug = [
'exercise_summary',
'exercise_skill_suggestions',
'exercise_instruction_rewrite',
].includes(selectedSlug)
const isPlanningPreviewSlug = selectedSlug.startsWith('planning_')
const loadList = useCallback(async () => {
const [pList, cat] = await Promise.all([
api.listAdminAiPrompts(),
@@ -133,15 +147,23 @@ export default function AdminAiPromptsPage() {
if (!detail?.id) return
setError('')
try {
const body = {
title: pvTitle,
goal: pvGoal,
execution: pvExec,
focus_hint: pvHint || undefined,
}
const fid = parseInt(String(pvFocusId).trim(), 10)
if (Number.isFinite(fid) && fid >= 1) {
body.focus_areas_context = [{ focus_area_id: fid, is_primary: true }]
const body = {}
if (isPlanningPreviewSlug) {
body.goal_query = pvGoalQuery.trim() || undefined
body.user_notes = pvUserNotes.trim() || undefined
const ms = parseInt(String(pvMaxSteps).trim(), 10)
if (Number.isFinite(ms) && ms >= 2 && ms <= 10) body.max_steps = ms
const sq = pvSearchQuery.trim()
if (sq) body.search_query = sq
} else if (isExercisePreviewSlug) {
body.title = pvTitle
body.goal = pvGoal
body.execution = pvExec
body.focus_hint = pvHint || undefined
const fid = parseInt(String(pvFocusId).trim(), 10)
if (Number.isFinite(fid) && fid >= 1) {
body.focus_areas_context = [{ focus_area_id: fid, is_primary: true }]
}
}
const r = await api.previewAdminAiPrompt(detail.id, body)
setPvPreview(r)
@@ -171,8 +193,8 @@ export default function AdminAiPromptsPage() {
<h1 style={{ margin: 0, fontSize: '1.25rem' }}>KI Prompts</h1>
</div>
<p style={{ fontSize: '13px', color: 'var(--text3)', marginTop: 0 }}>
Datenbankvorlagen (<code>ai_prompts</code>) für Übungs-KI. Platzhalter im Mustache-Stil werden serverseitig
aufgelöst — die Vorschau unten ruft kein externes Modell auf.
Datenbankvorlagen (<code>ai_prompts</code>) für Übungs- und Planungs-KI. Platzhalter im Mustache-Stil werden
serverseitig aufgelöst — die Vorschau unten ruft kein externes Modell auf.
</p>
{error ? <p style={{ color: 'var(--danger)' }}>{error}</p> : null}
@@ -301,33 +323,89 @@ export default function AdminAiPromptsPage() {
<section style={{ marginTop: 20, paddingTop: 16, borderTop: '1px solid var(--border)' }}>
<h4 style={{ margin: '0 0 12px', fontSize: '15px' }}>Vorschau (ohne OpenRouter)</h4>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
<div className="form-row">
<label className="form-label">Titel</label>
<input className="form-input" value={pvTitle} onChange={(e) => setPvTitle(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Fokus-ID (optional, Retrieval‑Raster)</label>
<input
className="form-input"
placeholder="numerisch"
value={pvFocusId}
onChange={(e) => setPvFocusId(e.target.value)}
/>
</div>
</div>
<div className="form-row">
<label className="form-label">Fokus-Hinweistext</label>
<input className="form-input" value={pvHint} onChange={(e) => setPvHint(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Ziel (HTML möglich)</label>
<textarea className="form-input" rows={4} value={pvGoal} onChange={(e) => setPvGoal(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Durchführung (HTML möglich)</label>
<textarea className="form-input" rows={4} value={pvExec} onChange={(e) => setPvExec(e.target.value)} />
</div>
{isPlanningPreviewSlug ? (
<>
<p style={{ fontSize: 13, color: 'var(--text3)', marginTop: 0 }}>
Beispielkontext für Planungs-Prompts — echte Katalog-Auszüge aus der Datenbank, übrige Felder
sind repräsentative Demo-Daten.
</p>
<div className="form-row">
<label className="form-label">Zielanfrage (goal_query)</label>
<textarea
className="form-input"
rows={3}
value={pvGoalQuery}
onChange={(e) => setPvGoalQuery(e.target.value)}
/>
</div>
<div className="form-row">
<label className="form-label">Trainer-Notizen (user_notes)</label>
<textarea
className="form-input"
rows={2}
value={pvUserNotes}
onChange={(e) => setPvUserNotes(e.target.value)}
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
<div className="form-row">
<label className="form-label">max_steps (Roadmap)</label>
<input
className="form-input"
type="number"
min={2}
max={10}
value={pvMaxSteps}
onChange={(e) => setPvMaxSteps(e.target.value)}
/>
</div>
<div className="form-row">
<label className="form-label">Suchanfrage (optional)</label>
<input
className="form-input"
placeholder="Leer = goal_query"
value={pvSearchQuery}
onChange={(e) => setPvSearchQuery(e.target.value)}
/>
</div>
</div>
</>
) : isExercisePreviewSlug ? (
<>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
<div className="form-row">
<label className="form-label">Titel</label>
<input className="form-input" value={pvTitle} onChange={(e) => setPvTitle(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Fokus-ID (optional, Retrieval‑Raster)</label>
<input
className="form-input"
placeholder="numerisch"
value={pvFocusId}
onChange={(e) => setPvFocusId(e.target.value)}
/>
</div>
</div>
<div className="form-row">
<label className="form-label">Fokus-Hinweistext</label>
<input className="form-input" value={pvHint} onChange={(e) => setPvHint(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Ziel (HTML möglich)</label>
<textarea className="form-input" rows={4} value={pvGoal} onChange={(e) => setPvGoal(e.target.value)} />
</div>
<div className="form-row">
<label className="form-label">Durchführung (HTML möglich)</label>
<textarea className="form-input" rows={4} value={pvExec} onChange={(e) => setPvExec(e.target.value)} />
</div>
</>
) : (
<p style={{ fontSize: 13, color: 'var(--text3)' }}>
Für diesen Slug ist noch kein Beispielkontext hinterlegt — es wird nur das Roh-Template ohne
Ersetzung angezeigt.
</p>
)}
<button type="button" className="btn btn-secondary" onClick={() => runPreview()}>
Platzhalter auflösen
</button>