feat: POST /corrections/eo — Gemini transcription + DeepSeek EO — 84/84 tests

This commit is contained in:
Hermann_Kitio 2026-04-16 17:43:46 +03:00
parent 77d5a8373e
commit f4f8c55ce7
7 changed files with 422 additions and 2 deletions

View file

@ -17,6 +17,22 @@ export interface EERapport {
exercices: string[]
}
export interface EOCritere {
nom: string
score: number
commentaire: string
}
export interface EORapport {
score: number
nclc: number
criteres: EOCritere[]
erreurs: string[]
production_modele: string
suggestions_idees: string[]
exercices: string[]
}
const SYSTEM_PROMPT = `Tu es un examinateur officiel du TCF Canada (Test de connaissance du français).
Tu évalues une production écrite selon les 4 critères officiels de l'Expression Écrite :
1. Cohérence et cohésion
@ -89,3 +105,76 @@ export async function correctEE(contenu: string, tache: string): Promise<EERappo
return rapport
}
const SYSTEM_PROMPT_EO = `Tu es un examinateur officiel du TCF Canada (Test de connaissance du français).
Tu évalues une production orale à partir de sa transcription selon les 4 critères officiels de l'Expression Orale :
1. Cohérence et cohésion
2. Lexique (étendue et maîtrise du vocabulaire)
3. Morphosyntaxe (grammaire et structures)
4. Phonologie NOTE IMPORTANTE : ce critère est fixé à 0 car l'évaluation se fait sur une transcription textuelle, pas sur l'audio original. Mets toujours 0 pour ce critère.
Tu dois retourner un JSON strict avec cette structure exacte :
{
"score": <number 0-20>,
"nclc": <number 4-12>,
"criteres": [
{ "nom": "Cohérence et cohésion", "score": <number 0-5>, "commentaire": "<string>" },
{ "nom": "Lexique", "score": <number 0-5>, "commentaire": "<string>" },
{ "nom": "Morphosyntaxe", "score": <number 0-5>, "commentaire": "<string>" },
{ "nom": "Phonologie", "score": 0, "commentaire": "Non évalué sur transcription textuelle." }
],
"erreurs": ["<erreur 1>", "<erreur 2>", ...],
"production_modele": "<version corrigée de la transcription>",
"suggestions_idees": ["<idée 1>", "<idée 2>", ...],
"exercices": ["<exercice recommandé 1>", "<exercice recommandé 2>", ...]
}
Règles :
- score est la note globale sur 20 (basée uniquement sur les 3 critères évalués)
- nclc est le niveau NCLC estimé (entre 4 et 12)
- Phonologie est toujours à 0 avec le commentaire "Non évalué sur transcription textuelle."
- Retourne UNIQUEMENT le JSON, sans texte avant ni après`
export async function correctEO(transcript: string, tache: string): Promise<EORapport> {
const response = await fetch(`${DEEPSEEK_BASE_URL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${DEEPSEEK_API_KEY}`,
},
body: JSON.stringify({
model: 'deepseek-chat',
messages: [
{ role: 'system', content: SYSTEM_PROMPT_EO },
{
role: 'user',
content: `Tâche : ${tache}\n\nTranscription de la production orale :\n${transcript}`,
},
],
temperature: 0.3,
response_format: { type: 'json_object' },
}),
})
if (!response.ok) {
throw new Error(`DeepSeek API error: ${response.status} ${response.statusText}`)
}
const data = await response.json()
const content = data.choices?.[0]?.message?.content
if (!content) {
throw new Error('DeepSeek API: réponse vide')
}
const rapport: EORapport = JSON.parse(content)
if (rapport.score < 0 || rapport.score > 20) {
throw new Error(`Score invalide: ${rapport.score} (attendu 0-20)`)
}
if (rapport.nclc < 4 || rapport.nclc > 12) {
throw new Error(`NCLC invalide: ${rapport.nclc} (attendu 4-12)`)
}
return rapport
}