Mehdi commited on
Commit
490c5f1
·
1 Parent(s): eb2f556

fix: force English output in all LLM prompts regardless of PDF language

Browse files

Questions, MCQ options, explanations and feedback are now always
generated in English even when the source PDF is in French or another language.

Files changed (2) hide show
  1. core/evaluator.py +3 -25
  2. core/questioner.py +2 -2
core/evaluator.py CHANGED
@@ -20,6 +20,7 @@ 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}
@@ -36,36 +37,13 @@ Evaluate the answer using this exact structure:
36
  3. What was missing or imprecise.
37
  4. A concise model answer (2-4 sentences).
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(),
 
20
 
21
  _PROMPT_EN = """\
22
  You are a patient and constructive university tutor.
23
+ IMPORTANT: Always write your entire response in English, even if the source material or student answer is in another language.
24
 
25
  Source material:
26
  {chunk}
 
37
  3. What was missing or imprecise.
38
  4. A concise model answer (2-4 sentences).
39
 
40
+ Be encouraging and specific. Write in English only."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ prompt = _PROMPT_EN.format(
 
47
  chunk=chunk.strip(),
48
  question=question.strip(),
49
  answer=student_answer.strip(),
core/questioner.py CHANGED
@@ -33,7 +33,7 @@ Rules:
33
  - ONE question only, on ONE concept
34
  - Maximum 25 words
35
  - No sub-questions, no "and", no compound questions
36
- - Write in {language}
37
  - Output only the question, nothing else
38
 
39
  Excerpt:
@@ -50,7 +50,7 @@ Rules:
50
  - One clear question, maximum 25 words
51
  - Exactly 4 options (A, B, C, D), only ONE is correct
52
  - All wrong options must be plausible — no obviously wrong answers
53
- - Write in {language}
54
  - For each option, write a 1-sentence explanation of why it is correct or incorrect
55
 
56
  Output format (use EXACTLY these labels, one per line, nothing else):
 
33
  - ONE question only, on ONE concept
34
  - Maximum 25 words
35
  - No sub-questions, no "and", no compound questions
36
+ - IMPORTANT: Always write the question in English, even if the source text is in another language
37
  - Output only the question, nothing else
38
 
39
  Excerpt:
 
50
  - One clear question, maximum 25 words
51
  - Exactly 4 options (A, B, C, D), only ONE is correct
52
  - All wrong options must be plausible — no obviously wrong answers
53
+ - IMPORTANT: Always write everything in English, even if the source text is in another language
54
  - For each option, write a 1-sentence explanation of why it is correct or incorrect
55
 
56
  Output format (use EXACTLY these labels, one per line, nothing else):