ruslanmv commited on
Commit
9b9e882
·
verified ·
1 Parent(s): d282daf

Update tool2.py

Browse files
Files changed (1) hide show
  1. tool2.py +4 -4
tool2.py CHANGED
@@ -39,14 +39,14 @@ def display_question(index, audio_enabled, selected_questions):
39
  return "Question index out of range.", [], None
40
 
41
  def get_explanation_and_answer(index, selected_questions):
42
- """Retrieves the explanation and correct answer for a given question index, handling missing explanations."""
43
  if 0 <= index < len(selected_questions):
44
  question_data = selected_questions[index]
45
- # Use get() with a default value to handle missing 'explanation' key
46
  explanation = question_data.get("explanation", "No explanation available.")
47
- correct_answer = question_data["answer"] # Assume 'answer' key always exists
48
  return explanation, correct_answer
49
- return "No explanation available.", ""
50
 
51
  # Text-to-speech function with rate limiting, retry mechanism, and client rotation
52
  import time
 
39
  return "Question index out of range.", [], None
40
 
41
  def get_explanation_and_answer(index, selected_questions):
42
+ """Retrieves the explanation and correct answer for a given question index, handling missing keys."""
43
  if 0 <= index < len(selected_questions):
44
  question_data = selected_questions[index]
45
+ # Use get() with a default value to handle missing keys
46
  explanation = question_data.get("explanation", "No explanation available.")
47
+ correct_answer = question_data.get("answer", "No answer available.") # Also handle missing answer key
48
  return explanation, correct_answer
49
+ return "No explanation available.", "No answer available."
50
 
51
  # Text-to-speech function with rate limiting, retry mechanism, and client rotation
52
  import time