abhiimanyu commited on
Commit
2fb5642
·
verified ·
1 Parent(s): fa70373

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -14,7 +14,7 @@ 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. 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"
@@ -22,31 +22,30 @@ def format_prompt(topic, description, difficulty):
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
 
@@ -54,6 +53,7 @@ def format_prompt(topic, description, difficulty):
54
 
55
 
56
 
 
57
  # The function to generate learning content based on the inputs
58
  def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
59
  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 adhere to the following JSON structure:\n\n"
20
  f"{{\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 and engaging language.]\"\n"
26
  f" }}\n"
27
  f" ]\n"
28
  f"}}\n\n"
29
  f"### Important Guidelines:\n"
30
+ f"1. Return only a valid JSON object with no additional text, explanations, or symbols.\n"
31
+ f"2. Do not include formatting like ```json or any other delimiters.\n"
32
+ f"3. Ensure all keys and values are properly enclosed in double quotes.\n"
33
+ f"4. Validate the JSON before returning it to ensure it is syntactically correct and complete.\n"
34
+ f"5. Do not use any extra characters like or </s>.\n"
 
35
  f"### Example Output:\n"
36
  f"{{\n"
37
  f" \"title\": \"Understanding the Basics of Thermodynamics\",\n"
38
  f" \"sections\": [\n"
39
  f" {{\n"
40
  f" \"subheading\": \"What is Thermodynamics?\",\n"
41
+ f" \"content\": \"Thermodynamics is the study of energy, heat, and how they interact. It explains phenomena like ice melting or engines running.\"\n"
42
  f" }},\n"
43
  f" {{\n"
44
+ f" \"subheading\": \"The Four Laws of Thermodynamics\",\n"
45
+ f" \"content\": \"The four laws govern how energy moves and changes. For example, the first law states that energy cannot be created or destroyed, only transformed.\"\n"
46
  f" }}\n"
47
  f" ]\n"
48
+ f"}}"
49
  )
50
  return prompt
51
 
 
53
 
54
 
55
 
56
+
57
  # The function to generate learning content based on the inputs
58
  def generate_learning_content(topic, description, difficulty, temperature=0.9, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.2):
59
  temperature = max(float(temperature), 1e-2) # Ensure minimum temperature