Spaces:
Runtime error
Runtime error
Download utils/prompts.py from dwaynefernandes05/EduGenerator: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/spaces/dwaynefernandes05/EduGenerator/resolve/main/utils/prompts.py
- Command line
-
hf download hf://spaces/dwaynefernandes05/EduGenerator/utils/prompts.py
-
curl -L -o prompts.py https://huggingface.co/spaces/dwaynefernandes05/EduGenerator/resolve/main/utils/prompts.py
3.42 kB
| """Centralized prompts for the Generator and Reviewer agents. | |
| All prompts live here to keep the rest of the code clean and deterministic. | |
| We are very strict about JSON-only outputs. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| from typing import Any, Dict, List, Optional | |
| JSON_ONLY_RULES = ( | |
| "You MUST respond with valid JSON only. " | |
| "Do NOT include markdown. Do NOT include any extra keys. " | |
| "Do NOT add commentary outside the JSON." | |
| ) | |
| def generator_system_prompt() -> str: | |
| schema_example = { | |
| "explanation": "string", | |
| "mcqs": [ | |
| { | |
| "question": "string", | |
| "options": [ | |
| "Option 1 text", | |
| "Option 2 text", | |
| "Option 3 text", | |
| "Option 4 text", | |
| ], | |
| "answer": "Option 2 text", | |
| } | |
| ], | |
| } | |
| return ( | |
| "You are the Generator Agent. Your job is to create accurate, age-appropriate educational content. " | |
| + JSON_ONLY_RULES | |
| + "\n\n" | |
| + "Output schema (MUST match exactly):\n" | |
| + json.dumps(schema_example, ensure_ascii=False) | |
| + "\n\n" | |
| + "Hard rules:\n" | |
| + "- Keep language appropriate for the given grade.\n" | |
| + "- Explanation must only cover concepts you will test in MCQs.\n" | |
| + "- MCQs must have exactly 4 options (strings).\n" | |
| + "- `answer` MUST be EXACTLY one of the strings in `options` (copy/paste match).\n" | |
| + "- Do NOT return A/B/C/D as the answer unless the option text is literally 'A', 'B', 'C', or 'D'.\n" | |
| + "- Do not vary the structure.\n" | |
| ) | |
| def generator_user_prompt(grade: int, topic: str, feedback: Optional[List[str]] = None) -> str: | |
| payload: Dict[str, Any] = {"grade": grade, "topic": topic} | |
| if feedback: | |
| payload["reviewer_feedback"] = feedback | |
| return ( | |
| "Generate educational content for the following input (JSON):\n" | |
| + json.dumps(payload, ensure_ascii=False) | |
| + "\n\n" | |
| + "If reviewer_feedback is provided, fix those issues while keeping the SAME output schema." | |
| ) | |
| def reviewer_system_prompt() -> str: | |
| schema_example = { | |
| "status": "pass", | |
| "feedback": ["Sentence 2 is too complex for Grade 4"], | |
| } | |
| return ( | |
| "You are the Reviewer Agent. You evaluate the Generator's JSON output. " | |
| + JSON_ONLY_RULES | |
| + "\n\n" | |
| + "Output schema (MUST match exactly):\n" | |
| + json.dumps(schema_example, ensure_ascii=False) | |
| + "\n\n" | |
| + "Evaluation criteria:\n" | |
| + "- Age appropriateness for the given grade\n" | |
| + "- Conceptual correctness\n" | |
| + "- Clarity\n" | |
| + "- Alignment between explanation and MCQs (MCQs must only test introduced concepts)\n" | |
| + "\n" | |
| + "If anything is wrong, set status='fail' and list concrete issues in feedback. " | |
| + "If everything is good, status='pass' and feedback should be an empty list." | |
| ) | |
| def reviewer_user_prompt(grade: int, topic: str, generator_output: Dict[str, Any]) -> str: | |
| """Provide review context, including grade/topic, so the reviewer can judge appropriateness.""" | |
| payload = { | |
| "grade": grade, | |
| "topic": topic, | |
| "generator_output": generator_output, | |
| } | |
| return "Review the following (JSON):\n" + json.dumps(payload, ensure_ascii=False) | |