Rathapoom commited on
Commit
d8f8ded
·
verified ·
1 Parent(s): 5eb9405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -78,13 +78,19 @@ def generate_questions_with_retry(knowledge_material, question_type, cognitive_l
78
  temperature=0.7 # Controls randomness
79
  )
80
  return response.choices[0].text # Extract the text from the API response
81
- except openai.error.APIError as e:
82
  retries += 1
83
  time.sleep(2) # Wait for 2 seconds before retrying
84
  st.error(f"Failed to connect to OpenAI API: {str(e)}")
85
  if retries == max_retries:
86
  st.error("Failed to connect to OpenAI API after several attempts.")
87
  return None
 
 
 
 
 
 
88
 
89
  # Main logic for the app
90
  if 'username' not in st.session_state:
 
78
  temperature=0.7 # Controls randomness
79
  )
80
  return response.choices[0].text # Extract the text from the API response
81
+ except openai.APIConnectionError as e:
82
  retries += 1
83
  time.sleep(2) # Wait for 2 seconds before retrying
84
  st.error(f"Failed to connect to OpenAI API: {str(e)}")
85
  if retries == max_retries:
86
  st.error("Failed to connect to OpenAI API after several attempts.")
87
  return None
88
+ except openai.RateLimitError as e:
89
+ st.error(f"Rate limit reached: {str(e)}")
90
+ return None
91
+ except openai.APIError as e:
92
+ st.error(f"API Error: {str(e)}")
93
+ return None
94
 
95
  # Main logic for the app
96
  if 'username' not in st.session_state: