Chad commited on
Commit
8d46470
·
1 Parent(s): a3728af

45672uwwewewewedwdwdwd

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -45,24 +45,25 @@ def generate_reply(user_input, chat_history):
45
  return chat_history, chat_history, ""
46
 
47
  def generate_quiz(subject, num_questions):
48
- quiz_questions = []
49
  try:
50
- for i in range(num_questions):
51
- prompt = f"Generate a multiple-choice history question about {subject}. Provide the question, four options labeled A, B, C, and D. After providing the quiz add 5 new lines and then add all of the answers for the quiz in the following format Answers: (Question 1 - a, Question 2 - d ...and so on for each question)"
52
- response = client.chat.completions.create(
53
- model="llama3-70b-8192",
54
- messages=[{"role": "user", "content": prompt}],
55
- temperature=0.7,
56
- max_completion_tokens=256,
57
- top_p=0.95,
58
- stream=False,
59
- stop=None,
60
- )
61
- question = response.choices[0].message.content or "Error generating question."
62
- quiz_questions.append(question)
63
  except Exception as error:
64
- quiz_questions.append(f"Error: {error}")
65
- return "\n\n".join(quiz_questions)
 
66
 
67
  def toggle_language(language):
68
  """Toggle UI elements between English and French."""
 
45
  return chat_history, chat_history, ""
46
 
47
  def generate_quiz(subject, num_questions):
48
+ """Generate a history quiz with multiple-choice questions."""
49
  try:
50
+ prompt = f"Generate {num_questions} multiple-choice history questions about {subject}. "
51
+ prompt += "For each question, provide the question text, four options labeled A, B, C, and D, and at the end of all questions, list the correct answers in the format: 'Correct Answers: X, Y, Z, ...'."
52
+
53
+ response = client.chat.completions.create(
54
+ model="llama3-70b-8192",
55
+ messages=[{"role": "user", "content": prompt}],
56
+ temperature=0.7,
57
+ max_completion_tokens=1024,
58
+ top_p=0.95,
59
+ stream=False,
60
+ stop=None,
61
+ )
62
+ quiz_content = response.choices[0].message.content or "Error generating quiz."
63
  except Exception as error:
64
+ quiz_content = f"Error: {error}"
65
+
66
+ return quiz_content
67
 
68
  def toggle_language(language):
69
  """Toggle UI elements between English and French."""