feat(sujets): POST /sujets/idees — suggestions DeepSeek (G5)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ecb478e10c
commit
bd8ab4b72b
2 changed files with 129 additions and 0 deletions
|
|
@ -146,6 +146,67 @@ Règles :
|
|||
- Phonologie est toujours à 0 avec le commentaire "Non évalué sur transcription textuelle."
|
||||
- Retourne UNIQUEMENT le JSON, sans texte avant ni après`
|
||||
|
||||
const SYSTEM_PROMPT_IDEES = `Tu es un coach TCF Canada. Tu aides un étudiant à continuer sa rédaction en cours.
|
||||
Tu dois retourner UNIQUEMENT un JSON strict : { "idees": ["<idée 1>", "<idée 2>", ...] }
|
||||
|
||||
Règles :
|
||||
- Exactement 5 idées courtes et concrètes (1 phrase max chacune)
|
||||
- Les idées doivent prolonger ce que l'étudiant a déjà écrit, sans répéter
|
||||
- Rester en français, ton encourageant, orienté action
|
||||
- Aucun texte avant ni après le JSON`
|
||||
|
||||
export async function generateIdees(consigne: string, contenu: string): Promise<string[]> {
|
||||
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_IDEES },
|
||||
{
|
||||
role: 'user',
|
||||
content: `Sujet : ${consigne}\n\nCe que l'étudiant a écrit jusqu'ici :\n${contenu}`,
|
||||
},
|
||||
],
|
||||
temperature: 0.5,
|
||||
response_format: { type: 'json_object' },
|
||||
}),
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`DeepSeek API error: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
const data = (await response.json()) as {
|
||||
choices?: { message?: { content?: string } }[]
|
||||
}
|
||||
const content = data.choices?.[0]?.message?.content
|
||||
|
||||
if (!content) {
|
||||
throw new Error('DeepSeek API: réponse vide')
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(content) as { idees?: unknown }
|
||||
|
||||
if (!Array.isArray(parsed.idees) || parsed.idees.length === 0) {
|
||||
throw new Error('Réponse DeepSeek invalide : idees doit être un tableau non vide')
|
||||
}
|
||||
|
||||
const idees = parsed.idees.filter(
|
||||
(i): i is string => typeof i === 'string' && i.trim().length > 0,
|
||||
)
|
||||
|
||||
if (idees.length === 0) {
|
||||
throw new Error('Réponse DeepSeek invalide : aucune idée exploitable')
|
||||
}
|
||||
|
||||
return idees
|
||||
}
|
||||
|
||||
export async function correctEO(transcript: string, tache: string): Promise<EORapport> {
|
||||
const response = await fetch(`${DEEPSEEK_BASE_URL}/chat/completions`, {
|
||||
method: 'POST',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue