Denysyk commited on
Commit
3a4d366
·
verified ·
1 Parent(s): 5a5c4a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -25,7 +25,20 @@ def init_exam(api_key: str):
25
  return [{"role": "assistant", "content": opening}], gr.update(interactive=True)
26
  except Exception as e:
27
  _agent = None
28
- return [{"role": "assistant", "content": f"Error initialising agent: {e}"}], gr.update(interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  def user_message(message: str, history: list):
@@ -53,7 +66,15 @@ def user_message(message: str, history: list):
53
  try:
54
  reply = _agent.chat(message)
55
  except Exception as e:
56
- reply = f"Agent error: {e}"
 
 
 
 
 
 
 
 
57
 
58
  history = history + [{"role": "assistant", "content": reply}]
59
  return history, ""
 
25
  return [{"role": "assistant", "content": opening}], gr.update(interactive=True)
26
  except Exception as e:
27
  _agent = None
28
+ err = str(e)
29
+ if "401" in err or "invalid_api_key" in err or "Invalid API Key" in err:
30
+ msg = "Invalid API key. Please check your Groq API key at console.groq.com and try again."
31
+ elif "429" in err or "rate_limit" in err:
32
+ msg = "Rate limit reached. Your daily token quota is exhausted. Please wait until tomorrow or upgrade your Groq plan."
33
+ elif "403" in err:
34
+ msg = "Access denied. Your API key does not have permission to use this model."
35
+ elif "404" in err:
36
+ msg = "Model not found. Please contact support."
37
+ elif "connection" in err.lower() or "timeout" in err.lower():
38
+ msg = "Connection error. Please check your internet connection and try again."
39
+ else:
40
+ msg = f"Error: {e}"
41
+ return [{"role": "assistant", "content": msg}], gr.update(interactive=False)
42
 
43
 
44
  def user_message(message: str, history: list):
 
66
  try:
67
  reply = _agent.chat(message)
68
  except Exception as e:
69
+ err = str(e)
70
+ if "429" in err or "rate_limit" in err:
71
+ reply = "Rate limit reached. Daily quota exhausted — please try again tomorrow."
72
+ elif "401" in err or "invalid_api_key" in err:
73
+ reply = "Invalid API key. Please restart and enter a valid Groq key."
74
+ elif "connection" in err.lower() or "timeout" in err.lower():
75
+ reply = "Connection error. Please check your internet and try again."
76
+ else:
77
+ reply = f"Agent error: {e}"
78
 
79
  history = history + [{"role": "assistant", "content": reply}]
80
  return history, ""