Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -73,18 +73,17 @@ def generate_question_with_chatgpt(context, topic):
|
|
73 |
print("API Response:", result) # Print the API response for debugging
|
74 |
|
75 |
# Modify the logic based on the actual structure of the 'result'
|
76 |
-
if 'choices' in result:
|
77 |
-
|
78 |
-
if
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
generated_question['correct_answer'] = correct_answer
|
88 |
|
89 |
return generated_question
|
90 |
|
|
|
73 |
print("API Response:", result) # Print the API response for debugging
|
74 |
|
75 |
# Modify the logic based on the actual structure of the 'result'
|
76 |
+
if 'choices' in result and isinstance(result['choices'], list) and result['choices']:
|
77 |
+
choice = result['choices'][0]
|
78 |
+
if 'message' in choice and isinstance(choice['message'], dict):
|
79 |
+
message = choice['message']
|
80 |
+
content = message.get('content', "Unable to generate a question..")
|
81 |
+
options = message.get('options', [])
|
82 |
+
correct_answer = message.get('correct_answer', "Unknown")
|
83 |
+
|
84 |
+
generated_question['content'] = content
|
85 |
+
generated_question['options'] = options
|
86 |
+
generated_question['correct_answer'] = correct_answer
|
|
|
87 |
|
88 |
return generated_question
|
89 |
|