StanDataCamp commited on
Commit
4840462
·
1 Parent(s): f86d663

Update model to gpt-4.1-mini and enhance error handling in explain_concept function

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -75,7 +75,7 @@ def explain_concept(question, level, language):
75
  try:
76
  # Generate streaming explanation using OpenAI API
77
  stream = client.chat.completions.create(
78
- model="gpt-4.1",
79
  messages=[
80
  {"role": "system", "content": system_prompt},
81
  {"role": "user", "content": question}
@@ -94,7 +94,18 @@ def explain_concept(question, level, language):
94
  yield partial
95
 
96
  except Exception as e:
97
- yield f"❌ Error generating explanation: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  # Create enhanced Gradio interface with modern styling
100
  with gr.Blocks(
 
75
  try:
76
  # Generate streaming explanation using OpenAI API
77
  stream = client.chat.completions.create(
78
+ model="gpt-4.1-mini",
79
  messages=[
80
  {"role": "system", "content": system_prompt},
81
  {"role": "user", "content": question}
 
94
  yield partial
95
 
96
  except Exception as e:
97
+ # Provide more specific error messages for common issues
98
+ error_msg = str(e).lower()
99
+ if "connection" in error_msg or "timeout" in error_msg:
100
+ yield "❌ Connection error: Unable to reach OpenAI API. Please check your internet connection and try again."
101
+ elif "api key" in error_msg or "authentication" in error_msg:
102
+ yield "❌ Authentication error: Invalid API key. Please check your OpenAI API key configuration."
103
+ elif "rate limit" in error_msg:
104
+ yield "❌ Rate limit exceeded: Too many requests. Please wait a moment and try again."
105
+ elif "model" in error_msg:
106
+ yield "❌ Model error: The specified model is not available. Please try again later."
107
+ else:
108
+ yield f"❌ Error generating explanation: {str(e)}"
109
 
110
  # Create enhanced Gradio interface with modern styling
111
  with gr.Blocks(