yangtb24 commited on
Commit
0da0e77
·
verified ·
1 Parent(s): cd15040

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -581,6 +581,46 @@ def handsome_chat_completions():
581
  "Content-Type": "application/json"
582
  }
583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
  if model_name in image_models:
585
  # Handle image generation
586
  # Map OpenAI-style parameters to SiliconFlow's parameters
 
581
  "Content-Type": "application/json"
582
  }
583
 
584
+ if model_name in image_models:
585
+ # Handle image generation
586
+ # Map OpenAI-style parameters to SiliconFlow's parameters
587
+ siliconflow_data = {
588
+ "model": model_name,
589
+ @app.route('/handsome/v1/chat/completions', methods=['POST'])
590
+ def handsome_chat_completions():
591
+ if not check_authorization(request):
592
+ return jsonify({"error": "Unauthorized"}), 401
593
+
594
+ data = request.get_json()
595
+ if not data or 'model' not in data:
596
+ return jsonify({"error": "Invalid request data"}), 400
597
+
598
+ model_name = data['model']
599
+
600
+ request_type = determine_request_type(
601
+ model_name,
602
+ text_models + image_models,
603
+ free_text_models + free_image_models
604
+ )
605
+
606
+ api_key = select_key(request_type, model_name)
607
+
608
+ if not api_key:
609
+ return jsonify(
610
+ {
611
+ "error": (
612
+ "No available API key for this "
613
+ "request type or all keys have "
614
+ "reached their limits"
615
+ )
616
+ }
617
+ ), 429
618
+
619
+ headers = {
620
+ "Authorization": f"Bearer {api_key}",
621
+ "Content-Type": "application/json"
622
+ }
623
+
624
  if model_name in image_models:
625
  # Handle image generation
626
  # Map OpenAI-style parameters to SiliconFlow's parameters