Spaces:
Running on Zero
Running on Zero
Mehdi commited on
Commit ·
5e6ff7d
1
Parent(s): 202248a
fix: prompts évaluateur séparés EN/FR pour forcer la langue du feedback
Browse files- core/evaluator.py +26 -5
core/evaluator.py
CHANGED
|
@@ -18,9 +18,8 @@ Public API:
|
|
| 18 |
|
| 19 |
from model.llm import get_llm
|
| 20 |
|
| 21 |
-
|
| 22 |
You are a patient and constructive university tutor.
|
| 23 |
-
IMPORTANT: You must write your ENTIRE response in {language}. Every word, every label, every sentence must be in {language}. Do not use any other language.
|
| 24 |
|
| 25 |
Source material:
|
| 26 |
{chunk}
|
|
@@ -31,7 +30,7 @@ Question asked to the student:
|
|
| 31 |
Student's answer:
|
| 32 |
{answer}
|
| 33 |
|
| 34 |
-
Evaluate the answer
|
| 35 |
1. Verdict: Correct / Partially correct / Incorrect
|
| 36 |
2. What was good about the answer.
|
| 37 |
3. What was missing or imprecise.
|
|
@@ -39,14 +38,36 @@ Evaluate the answer. Structure your response as:
|
|
| 39 |
|
| 40 |
Be encouraging and specific."""
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def evaluate_answer(question: str, chunk: str, student_answer: str, language: str = "English") -> str:
|
| 44 |
"""Return structured feedback for *student_answer* given *question* and *chunk*."""
|
| 45 |
llm = get_llm()
|
| 46 |
-
|
|
|
|
| 47 |
chunk=chunk.strip(),
|
| 48 |
question=question.strip(),
|
| 49 |
answer=student_answer.strip(),
|
| 50 |
-
language=language,
|
| 51 |
)
|
| 52 |
return llm.generate(prompt).strip()
|
|
|
|
| 18 |
|
| 19 |
from model.llm import get_llm
|
| 20 |
|
| 21 |
+
_PROMPT_EN = """\
|
| 22 |
You are a patient and constructive university tutor.
|
|
|
|
| 23 |
|
| 24 |
Source material:
|
| 25 |
{chunk}
|
|
|
|
| 30 |
Student's answer:
|
| 31 |
{answer}
|
| 32 |
|
| 33 |
+
Evaluate the answer using this exact structure:
|
| 34 |
1. Verdict: Correct / Partially correct / Incorrect
|
| 35 |
2. What was good about the answer.
|
| 36 |
3. What was missing or imprecise.
|
|
|
|
| 38 |
|
| 39 |
Be encouraging and specific."""
|
| 40 |
|
| 41 |
+
_PROMPT_FR = """\
|
| 42 |
+
Tu es un tuteur universitaire patient et constructif.
|
| 43 |
+
|
| 44 |
+
Matériel source :
|
| 45 |
+
{chunk}
|
| 46 |
+
|
| 47 |
+
Question posée à l'étudiant :
|
| 48 |
+
{question}
|
| 49 |
+
|
| 50 |
+
Réponse de l'étudiant :
|
| 51 |
+
{answer}
|
| 52 |
+
|
| 53 |
+
Évalue la réponse en respectant exactement cette structure :
|
| 54 |
+
1. Verdict : Correct / Partiellement correct / Incorrect
|
| 55 |
+
2. Ce qui était bien dans la réponse.
|
| 56 |
+
3. Ce qui manquait ou était imprécis.
|
| 57 |
+
4. Une réponse modèle concise (2-4 phrases).
|
| 58 |
+
|
| 59 |
+
Sois encourageant et précis."""
|
| 60 |
+
|
| 61 |
+
_TEMPLATES = {"English": _PROMPT_EN, "Français": _PROMPT_FR}
|
| 62 |
+
|
| 63 |
|
| 64 |
def evaluate_answer(question: str, chunk: str, student_answer: str, language: str = "English") -> str:
|
| 65 |
"""Return structured feedback for *student_answer* given *question* and *chunk*."""
|
| 66 |
llm = get_llm()
|
| 67 |
+
template = _TEMPLATES.get(language, _PROMPT_EN)
|
| 68 |
+
prompt = template.format(
|
| 69 |
chunk=chunk.strip(),
|
| 70 |
question=question.strip(),
|
| 71 |
answer=student_answer.strip(),
|
|
|
|
| 72 |
)
|
| 73 |
return llm.generate(prompt).strip()
|