Chad commited on
Commit ·
0bb2945
1
Parent(s): f8a3614
testing3
Browse files
app.py
CHANGED
|
@@ -44,13 +44,18 @@ def generate_reply(user_input, chat_history):
|
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
|
| 47 |
-
def generate_quiz(subject, num_questions, chat_history):
|
| 48 |
"""Generate a history quiz with multiple-choice questions and append it to the chat."""
|
| 49 |
try:
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
response = client.chat.completions.create(
|
| 55 |
model="llama3-70b-8192",
|
| 56 |
messages=[{"role": "user", "content": prompt}],
|
|
@@ -151,7 +156,7 @@ with gr.Blocks() as interface:
|
|
| 151 |
|
| 152 |
quiz_button.click(
|
| 153 |
fn=generate_quiz,
|
| 154 |
-
inputs=[quiz_subject, quiz_num_questions,state],
|
| 155 |
outputs=[chatbot, state]
|
| 156 |
)
|
| 157 |
|
|
|
|
| 44 |
chat_history.append({"role": "assistant", "content": reply})
|
| 45 |
return chat_history, chat_history, ""
|
| 46 |
|
| 47 |
+
def generate_quiz(subject, num_questions, chat_history, language_state):
|
| 48 |
"""Generate a history quiz with multiple-choice questions and append it to the chat."""
|
| 49 |
try:
|
| 50 |
+
if language_state == "english":
|
| 51 |
+
prompt = f"Generate {num_questions} multiple-choice history questions about {subject}. "
|
| 52 |
+
prompt += "For each question, provide the question text, four options labeled A, B, C, and D, "
|
| 53 |
+
prompt += "and at the end of all questions, list the correct answers in the format: 'Correct Answers: X, Y, Z, ...'."
|
| 54 |
+
else:
|
| 55 |
+
prompt = f"Générez {num_questions} questions à choix multiples sur l'histoire de {subject}. "
|
| 56 |
+
prompt += "Pour chaque question, fournissez l'énoncé de la question, quatre options étiquetées A, B, C et D, "
|
| 57 |
+
prompt += "et à la fin de toutes les questions, listez les bonnes réponses au format : 'Réponses correctes : X, Y, Z, ...'."
|
| 58 |
+
|
| 59 |
response = client.chat.completions.create(
|
| 60 |
model="llama3-70b-8192",
|
| 61 |
messages=[{"role": "user", "content": prompt}],
|
|
|
|
| 156 |
|
| 157 |
quiz_button.click(
|
| 158 |
fn=generate_quiz,
|
| 159 |
+
inputs=[quiz_subject, quiz_num_questions,state,language_state],
|
| 160 |
outputs=[chatbot, state]
|
| 161 |
)
|
| 162 |
|