Spaces:
Sleeping
Sleeping
Update openai_llm.py
Browse filesUpdated the system prompt to make the structure more robust and increase the quality
- openai_llm.py +32 -26
openai_llm.py
CHANGED
|
@@ -16,36 +16,43 @@ class LessonPlanGenerator:
|
|
| 16 |
|
| 17 |
def generate_lesson_plan(self, topic):
|
| 18 |
system_prompt = """
|
| 19 |
-
You are an advanced lesson plan generator. When provided with an input text prompt
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
"""
|
|
|
|
| 43 |
try:
|
| 44 |
response = self.client.chat.completions.create(
|
| 45 |
model="gpt-4o-mini",
|
| 46 |
messages=[
|
| 47 |
{"role": "system", "content": system_prompt},
|
| 48 |
-
{"role": "user", "content":
|
| 49 |
],
|
| 50 |
response_format={"type": "json_object"} # This ensures JSON output
|
| 51 |
)
|
|
@@ -55,5 +62,4 @@ class LessonPlanGenerator:
|
|
| 55 |
return json.loads(response.choices[0].message.content, strict=True)
|
| 56 |
|
| 57 |
except Exception as e:
|
| 58 |
-
return {"error": str(e)}
|
| 59 |
-
|
|
|
|
| 16 |
|
| 17 |
def generate_lesson_plan(self, topic):
|
| 18 |
system_prompt = """
|
| 19 |
+
You are an advanced lesson plan generator. When provided with an input text prompt requesting a lesson plan on a specific topic, along with parameters such as learner age, proficiency level, duration, and technology usage, follow these steps:
|
| 20 |
+
|
| 21 |
+
1. **Extract Input Parameters:**
|
| 22 |
+
- Identify the topic, target learner group (age and proficiency level), lesson duration, and any technology requirements.
|
| 23 |
+
|
| 24 |
+
2. **Determine the Appropriate Framework:**3
|
| 25 |
+
- For young learners with clear sequential activities, use PPP (Presentation, Practice, Production) or ESA (Engage, Study, Activate). If flexibility is needed, use Boomerang ESA (introduces application before instruction) or Patchwork ESA (iterative reinforcement)
|
| 26 |
+
- For high school, advanced learners, or adult learners, use TBL (Task-Based Learning) to apply knowledge in real-world scenarios, reinforcing learning through collaborative problem-solving.
|
| 27 |
+
- For learners with prior knowledge, use TTT (Test, Teach, Test) to identify knowledge gaps, deliver targeted instruction, and reassess comprehension.
|
| 28 |
+
- For curriculum-focused or structured long-term learning, use UbD (Understanding by Design) to define learning outcomes first and align instructional activities accordingly.
|
| 29 |
+
3. **Generate a JSON Structure:**
|
| 30 |
+
- Your output should be a well-structured JSON object with sections in the following order:
|
| 31 |
+
- **Objectives and Learning Outcomes**
|
| 32 |
+
- **Essential Questions** (if using UbD)
|
| 33 |
+
- **Materials and Resources**
|
| 34 |
+
- **Lesson Plan Structure:**
|
| 35 |
+
Each subsection (e.g., Presentation, Engage, Study, Production, Activate) should follow this format in the following order:
|
| 36 |
+
- **Objective:** State the purpose of this section.
|
| 37 |
+
- **Key Parts (e.g., Part A, Part B ):** A very detailed description in bullet points explaining this section step by step
|
| 38 |
+
- **Activities (if applicable):** Provide a very detailed description of activities and their expected duration (e.g., "Discussion [10 minutes]").
|
| 39 |
+
- **Assessment Strategies**
|
| 40 |
+
- **Additional Relevant Details** based on the chosen framework.
|
| 41 |
+
|
| 42 |
+
4. Select the most effective framework while maintaining clarity and logical progression.
|
| 43 |
+
|
| 44 |
+
5. **Output Format:**
|
| 45 |
+
- **Well-structured, human-readable JSON** with clear section headings (e.g., "Materials and Resources" instead of camelCase).
|
| 46 |
+
- **Include time allocations in brackets** (e.g., "Reflection [5 min]").
|
| 47 |
+
|
| 48 |
"""
|
| 49 |
+
# - **Avoid excessive subheadings** such as 'Key Sections,' 'Subsections,' or 'Part.' Directly present relevant content under the appropriate headings.
|
| 50 |
try:
|
| 51 |
response = self.client.chat.completions.create(
|
| 52 |
model="gpt-4o-mini",
|
| 53 |
messages=[
|
| 54 |
{"role": "system", "content": system_prompt},
|
| 55 |
+
{"role": "user", "content": topic}
|
| 56 |
],
|
| 57 |
response_format={"type": "json_object"} # This ensures JSON output
|
| 58 |
)
|
|
|
|
| 62 |
return json.loads(response.choices[0].message.content, strict=True)
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
+
return {"error": str(e)}
|
|
|