Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,27 +14,30 @@ 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. Generate highly engaging and structured
|
| 18 |
f"Use the following description as context: '{description}'. "
|
| 19 |
-
f"The content should be suitable for a '{difficulty}' difficulty level and MUST strictly follow this
|
| 20 |
-
f"
|
| 21 |
-
f"
|
| 22 |
-
f"
|
| 23 |
-
f"
|
| 24 |
-
f"[
|
| 25 |
-
f"
|
| 26 |
-
f"
|
| 27 |
-
f"
|
| 28 |
-
f"
|
| 29 |
-
f"
|
| 30 |
-
f"
|
| 31 |
-
f"
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
return prompt
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
|
|
|
| 38 |
# The function to generate learning content based on the inputs
|
| 39 |
def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
|
| 40 |
temperature = max(float(temperature), 1e-2) # Ensure minimum temperature
|
|
|
|
| 14 |
# return prompt
|
| 15 |
def format_prompt(topic, description, difficulty):
|
| 16 |
prompt = (
|
| 17 |
+
f"You are an expert educator. Generate highly engaging, educational, and structured content on 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 follow this JSON structure:\n\n"
|
| 20 |
+
f"{{\n"
|
| 21 |
+
f" \"title\": \"[The title of the content]\",\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 in plain text]\"\n"
|
| 26 |
+
f" }}\n"
|
| 27 |
+
f" ]\n"
|
| 28 |
+
f"}}\n\n"
|
| 29 |
+
f"Ensure that:\n"
|
| 30 |
+
f"1. The output is a valid JSON object.\n"
|
| 31 |
+
f"2. The JSON structure includes a 'title' and a list of 'sections', where each section contains 'subheading' and 'content'.\n"
|
| 32 |
+
f"3. Do not include any extra text, explanations, or symbols outside the JSON structure.\n"
|
| 33 |
+
f"4. Validate the JSON before returning it to ensure it follows standard JSON formatting."
|
| 34 |
)
|
| 35 |
return prompt
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
+
|
| 41 |
# The function to generate learning content based on the inputs
|
| 42 |
def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
|
| 43 |
temperature = max(float(temperature), 1e-2) # Ensure minimum temperature
|