mohammed3536 commited on
Commit
fde8398
·
verified ·
1 Parent(s): fd906ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -39,7 +39,7 @@ def generate_mcqs_on_topic(text, topic, num_mcqs=5):
39
  def extract_options_and_correct_answer(api_response):
40
  if 'choices' in api_response:
41
  choices = api_response['choices']
42
- if choices:
43
  message = choices[0].get('message', {})
44
  content = message.get('content', "Unable to generate a question..")
45
  options = message.get('options', [])
@@ -49,6 +49,7 @@ def extract_options_and_correct_answer(api_response):
49
 
50
  return "Unexpected API response format.", [], "Unknown"
51
 
 
52
  def generate_question_with_chatgpt(context, topic):
53
  client = OpenAI()
54
  # Initializing the default value
 
39
  def extract_options_and_correct_answer(api_response):
40
  if 'choices' in api_response:
41
  choices = api_response['choices']
42
+ if isinstance(choices, list) and choices: # Check if 'choices' is a non-empty list
43
  message = choices[0].get('message', {})
44
  content = message.get('content', "Unable to generate a question..")
45
  options = message.get('options', [])
 
49
 
50
  return "Unexpected API response format.", [], "Unknown"
51
 
52
+
53
  def generate_question_with_chatgpt(context, topic):
54
  client = OpenAI()
55
  # Initializing the default value