Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,23 +14,39 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
| 14 |
# return prompt
|
| 15 |
def format_prompt(topic, description, difficulty):
|
| 16 |
prompt = (
|
| 17 |
-
f"You are an expert educator.
|
| 18 |
f"Use the following description as context: '{description}'. "
|
| 19 |
-
f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly
|
| 20 |
f"{{\n"
|
| 21 |
-
f" \"title\": \"[The title of the
|
| 22 |
f" \"sections\": [\n"
|
| 23 |
f" {{\n"
|
| 24 |
f" \"subheading\": \"[A clear subheading summarizing the section]\",\n"
|
| 25 |
-
f" \"content\": \"[Detailed explanation of the section content in
|
| 26 |
f" }}\n"
|
| 27 |
f" ]\n"
|
| 28 |
f"}}\n\n"
|
| 29 |
-
f"
|
| 30 |
-
f"1.
|
| 31 |
-
f"2.
|
| 32 |
-
f"3.
|
| 33 |
-
f"4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
return prompt
|
| 36 |
|
|
|
|
| 14 |
# return prompt
|
| 15 |
def format_prompt(topic, description, difficulty):
|
| 16 |
prompt = (
|
| 17 |
+
f"You are an expert educator. Your task is to generate structured educational content for the topic '{topic}'. "
|
| 18 |
f"Use the following description as context: '{description}'. "
|
| 19 |
+
f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly adhere to the following JSON structure:\n\n"
|
| 20 |
f"{{\n"
|
| 21 |
+
f" \"title\": \"[The title of the topic]\",\n"
|
| 22 |
f" \"sections\": [\n"
|
| 23 |
f" {{\n"
|
| 24 |
f" \"subheading\": \"[A clear subheading summarizing the section]\",\n"
|
| 25 |
+
f" \"content\": \"[Detailed explanation of the section content, written in simple language appropriate for an eighth-grader.]\"\n"
|
| 26 |
f" }}\n"
|
| 27 |
f" ]\n"
|
| 28 |
f"}}\n\n"
|
| 29 |
+
f"### Important Guidelines:\n"
|
| 30 |
+
f"1. **Do not include any text, context, or explanations outside the JSON structure.**\n"
|
| 31 |
+
f"2. **Ensure all content is enclosed within the JSON format and follows standard JSON syntax.**\n"
|
| 32 |
+
f"3. The response must contain a \"title\" field and a \"sections\" field, where \"sections\" is an array of objects.\n"
|
| 33 |
+
f"4. Each object in the \"sections\" array must contain a \"subheading\" and \"content\" field.\n"
|
| 34 |
+
f"5. Use simple, engaging, and educational language suitable for a young audience.\n"
|
| 35 |
+
f"6. Validate the JSON structure before returning it to ensure it is error-free and compliant with the format.\n"
|
| 36 |
+
f"### Example Output:\n"
|
| 37 |
+
f"{{\n"
|
| 38 |
+
f" \"title\": \"Understanding the Basics of Thermodynamics\",\n"
|
| 39 |
+
f" \"sections\": [\n"
|
| 40 |
+
f" {{\n"
|
| 41 |
+
f" \"subheading\": \"What is Thermodynamics?\",\n"
|
| 42 |
+
f" \"content\": \"Thermodynamics is the study of energy, heat, and how they work together. It's like understanding how heat flows when cooking or how machines use energy.\"\n"
|
| 43 |
+
f" }},\n"
|
| 44 |
+
f" {{\n"
|
| 45 |
+
f" \"subheading\": \"The First Law of Thermodynamics\",\n"
|
| 46 |
+
f" \"content\": \"The First Law says that energy cannot be created or destroyed. For example, when you eat food, your body converts that energy into movement.\"\n"
|
| 47 |
+
f" }}\n"
|
| 48 |
+
f" ]\n"
|
| 49 |
+
f"}}\n"
|
| 50 |
)
|
| 51 |
return prompt
|
| 52 |
|