mohammed3536 commited on
Commit
d660a3a
·
verified ·
1 Parent(s): 95a7b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
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
- choices = result['choices']
78
- if isinstance(choices, list) and choices: # Check if 'choices' is a non-empty list
79
- if 'message' in choices[0]:
80
- message = choices[0]['message']
81
- content = message.get('content', "Unable to generate a question..")
82
- options = message.get('options', [])
83
- correct_answer = message.get('correct_answer', "Unknown")
84
-
85
- generated_question['content'] = content
86
- generated_question['options'] = options
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