Ilke Ileri commited on
Commit
88b53d1
·
1 Parent(s): d54cae5

Add debug endpoint and improve error handling for Vapi troubleshooting

Browse files
Files changed (1) hide show
  1. app.py +34 -6
app.py CHANGED
@@ -55,6 +55,20 @@ def health_check():
55
  "base_model": BASE_MODEL
56
  }), 200
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  @app.route("/chat/completions", methods=["POST", "OPTIONS"])
59
  def chat_completions():
60
  # Log incoming request
@@ -62,7 +76,7 @@ def chat_completions():
62
  print(f"NEW REQUEST: {request.method} from {request.remote_addr}")
63
  print(f"Headers: {dict(request.headers)}")
64
  if request.method == "POST":
65
- print(f"Body: {request.get_data(as_text=True)[:200]}...")
66
  print("=" * 60)
67
 
68
  # OPTIONS isteği için preflight response
@@ -209,12 +223,26 @@ def chat_completions():
209
  except Exception as e:
210
  import traceback
211
  error_details = traceback.format_exc()
212
- print(f"Error: {str(e)}")
213
  print(f"Traceback: {error_details}")
214
- return jsonify({
215
- "error": str(e),
216
- "type": type(e).__name__
217
- }), 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  if __name__ == "__main__":
220
  app.run(host="0.0.0.0", port=7860)
 
55
  "base_model": BASE_MODEL
56
  }), 200
57
 
58
+ @app.route("/debug", methods=["POST"])
59
+ def debug_endpoint():
60
+ """Debug endpoint to see what Vapi is sending"""
61
+ try:
62
+ data = request.get_json()
63
+ headers = dict(request.headers)
64
+ return jsonify({
65
+ "received_data": data,
66
+ "received_headers": headers,
67
+ "status": "debug_ok"
68
+ }), 200
69
+ except Exception as e:
70
+ return jsonify({"error": str(e)}), 500
71
+
72
  @app.route("/chat/completions", methods=["POST", "OPTIONS"])
73
  def chat_completions():
74
  # Log incoming request
 
76
  print(f"NEW REQUEST: {request.method} from {request.remote_addr}")
77
  print(f"Headers: {dict(request.headers)}")
78
  if request.method == "POST":
79
+ print(f"Body: {request.get_data(as_text=True)[:500]}...")
80
  print("=" * 60)
81
 
82
  # OPTIONS isteği için preflight response
 
223
  except Exception as e:
224
  import traceback
225
  error_details = traceback.format_exc()
226
+ print(f"ERROR: {str(e)}")
227
  print(f"Traceback: {error_details}")
228
+
229
+ # Return error in both streaming and non-streaming format
230
+ error_response = {
231
+ "error": {
232
+ "message": str(e),
233
+ "type": type(e).__name__,
234
+ "code": "internal_error"
235
+ }
236
+ }
237
+
238
+ # If streaming was requested, return error in SSE format
239
+ if 'stream' in locals() and stream:
240
+ def error_stream():
241
+ yield f"data: {__import__('json').dumps(error_response)}\n\n"
242
+ yield "data: [DONE]\n\n"
243
+ return app.response_class(error_stream(), mimetype='text/event-stream')
244
+
245
+ return jsonify(error_response), 500
246
 
247
  if __name__ == "__main__":
248
  app.run(host="0.0.0.0", port=7860)