Rooni commited on
Commit
e930b46
·
1 Parent(s): ef69185

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -22,7 +22,12 @@ def generate_response(prompt):
22
  }
23
 
24
  response = requests.post(gpt_url, json=data, headers=headers)
25
- return response.json()["choices"][0]["text"].strip()
 
 
 
 
 
26
 
27
  # Создание интерфейса чата с использованием Gradio
28
  def chat_interface(messages):
 
22
  }
23
 
24
  response = requests.post(gpt_url, json=data, headers=headers)
25
+
26
+ # Проверяем наличие ключа 'choices' в ответе
27
+ if "choices" in response.json():
28
+ return response.json()["choices"][0]["text"].strip()
29
+ else:
30
+ return "Error: Unable to retrieve response."
31
 
32
  # Создание интерфейса чата с использованием Gradio
33
  def chat_interface(messages):