Gopala Krishna commited on
Commit
3be242c
·
1 Parent(s): 2f5ca58

added try except

Browse files
Files changed (2) hide show
  1. .vs/MyChatGPTTurbo/v17/.wsuo +0 -0
  2. app.py +4 -1
.vs/MyChatGPTTurbo/v17/.wsuo CHANGED
Binary files a/.vs/MyChatGPTTurbo/v17/.wsuo and b/.vs/MyChatGPTTurbo/v17/.wsuo differ
 
app.py CHANGED
@@ -14,7 +14,8 @@ else:
14
  {"role": "system", "content": "My AI Assistant"},
15
  ]
16
 
17
- def chatbot(input):
 
18
  if input:
19
  messages.append({"role": "user", "content": input})
20
  chat = openai.ChatCompletion.create(
@@ -23,6 +24,8 @@ else:
23
  reply = chat.choices[0].message.content
24
  messages.append({"role": "assistant", "content": reply})
25
  return reply
 
 
26
 
27
  gr.Interface(
28
  fn=chatbot,
 
14
  {"role": "system", "content": "My AI Assistant"},
15
  ]
16
 
17
+ def chatbot(input):
18
+ try:
19
  if input:
20
  messages.append({"role": "user", "content": input})
21
  chat = openai.ChatCompletion.create(
 
24
  reply = chat.choices[0].message.content
25
  messages.append({"role": "assistant", "content": reply})
26
  return reply
27
+ except openai.error.OpenAIError as e:
28
+ return "System is at capacity right now.Please try again later"
29
 
30
  gr.Interface(
31
  fn=chatbot,