Spaces:
Running
Running
Create QuizEngine.py
Browse files- src/core/QuizEngine.py +45 -0
src/core/QuizEngine.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
from core.AcronymManager import AcronymManager
|
| 3 |
+
|
| 4 |
+
class QuizEngine:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
# reuse the existing manager to load the JSON
|
| 7 |
+
self.acronym_mgr = AcronymManager()
|
| 8 |
+
|
| 9 |
+
def get_random_acronym(self):
|
| 10 |
+
"""
|
| 11 |
+
Fetches a random acronym-definition pair.
|
| 12 |
+
Returns: dict or None (if empty)
|
| 13 |
+
"""
|
| 14 |
+
if not self.acronym_mgr.acronyms:
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
+
# Pick a random key
|
| 18 |
+
acronym = random.choice(list(self.acronym_mgr.acronyms.keys()))
|
| 19 |
+
definition = self.acronym_mgr.acronyms[acronym]
|
| 20 |
+
|
| 21 |
+
return {
|
| 22 |
+
"type": "acronym",
|
| 23 |
+
"term": acronym,
|
| 24 |
+
"correct_definition": definition,
|
| 25 |
+
"question": f"What does **{acronym}** stand for?"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
def construct_grading_prompt(self, term, correct_definition, user_answer):
|
| 29 |
+
"""
|
| 30 |
+
Builds the prompt for the Board Examiner persona.
|
| 31 |
+
We return the string here so app.py can send it to whichever LLM is active.
|
| 32 |
+
"""
|
| 33 |
+
return (
|
| 34 |
+
f"You are a strict US Navy Engineering Duty Officer Board Examiner.\n"
|
| 35 |
+
f"I am a candidate. You asked me to define the acronym: {term}\n\n"
|
| 36 |
+
f"The Official Definition is: {correct_definition}\n"
|
| 37 |
+
f"My Answer was: {user_answer}\n\n"
|
| 38 |
+
f"INSTRUCTIONS:\n"
|
| 39 |
+
f"1. Grade my answer as PASS (Correct expansion) or FAIL (Incorrect expansion).\n"
|
| 40 |
+
f"2. If I got the words right but missed the full context, give me a 'PASS with Comments'.\n"
|
| 41 |
+
f"3. Keep your feedback short and military-professional.\n\n"
|
| 42 |
+
f"OUTPUT FORMAT:\n"
|
| 43 |
+
f"**GRADE:** [PASS/FAIL]\n"
|
| 44 |
+
f"**CRITIQUE:** [Your brief feedback]"
|
| 45 |
+
)
|