Niansuh commited on
Commit
0604f3f
·
verified ·
1 Parent(s): 5d52377

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -25,8 +25,16 @@ def proxy(endpoint):
25
  data = request.get_json()
26
  response = requests.post(f"{BASE_URL}/{endpoint}", headers=headers, json=data)
27
 
28
- # Return the OpenAI response
29
- return jsonify(response.json()), response.status_code
 
 
 
 
 
 
 
 
30
 
31
  if __name__ == "__main__":
32
  app.run(host="0.0.0.0", port=5000)
 
25
  data = request.get_json()
26
  response = requests.post(f"{BASE_URL}/{endpoint}", headers=headers, json=data)
27
 
28
+ # Handle non-JSON responses
29
+ try:
30
+ response_json = response.json()
31
+ except requests.exceptions.JSONDecodeError:
32
+ # Log the raw response text for debugging
33
+ print("Non-JSON response:", response.text)
34
+ return jsonify({"error": "Invalid response from OpenAI API", "details": response.text}), response.status_code
35
+
36
+ # Return the OpenAI response if it's JSON
37
+ return jsonify(response_json), response.status_code
38
 
39
  if __name__ == "__main__":
40
  app.run(host="0.0.0.0", port=5000)