feat: AI category matching — pass all categories to GPT for best-fit selection

Previously: heuristic text matching (sub_type in category.name) — failed
for semantic cases like 'Iran Ceasefire Talks' → 'Guerre — Moyen-Orient'.

Now: all EventCategories are sent in the prompt (name + type + description).
The AI picks matched_category by semantic understanding, returns it in JSON.
- Validates returned name against known categories (case-insensitive)
- Auto-sets event sub_type when AI finds a match and sub_type was empty
- Returns matched_category in evaluate response + shown in UI eval message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-25 22:02:47 +02:00
parent bf938067a1
commit 7eb8c24719
2 changed files with 94 additions and 53 deletions

View File

@@ -356,7 +356,8 @@ function EventDetail({
const r = await fetch(`/api/market-events/${event.id}/evaluate?force=${force}`, { method: 'POST' })
const d = await r.json()
if (!r.ok) throw new Error(d.detail || r.statusText)
setEvalMsg(`${d.n_instruments} instruments évalués`)
const catInfo = d.matched_category ? ` · catégorie: ${d.matched_category}` : ''
setEvalMsg(`${d.n_instruments} instruments évalués${catInfo}`)
await loadDetail()
} catch (e: any) {
setEvalMsg(`${e.message}`)