Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,93 +53,94 @@ def index():
|
|
| 53 |
@app.route('/v1/chat/completions', methods=['POST'])
|
| 54 |
@requires_api_key
|
| 55 |
def chat_completions(api_key):
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
| 143 |
|
| 144 |
@app.route('/rate_limit/status', methods=['GET'])
|
| 145 |
@requires_api_key
|
|
|
|
| 53 |
@app.route('/v1/chat/completions', methods=['POST'])
|
| 54 |
@requires_api_key
|
| 55 |
def chat_completions(api_key):
|
| 56 |
+
return jsonify({'detail': "YOUUUUUUUUUU"), 500
|
| 57 |
+
# logging.info("Received request for chat completions")
|
| 58 |
+
# print("requess received")
|
| 59 |
+
# try:
|
| 60 |
+
# logging.info("Received request for chat completions")
|
| 61 |
+
# # Parse and validate request data
|
| 62 |
+
# try:
|
| 63 |
+
# data = request.get_json()
|
| 64 |
+
# chat_request = ChatCompletionRequest(**data)
|
| 65 |
+
# except ValidationError as e:
|
| 66 |
+
# return jsonify({'detail': e.errors()}), 400
|
| 67 |
+
|
| 68 |
+
# # Check API key validity and rate limit
|
| 69 |
+
# is_valid, error_message = check_api_key_validity(api_key)
|
| 70 |
+
# if not is_valid:
|
| 71 |
+
# return jsonify({'detail': error_message}), 401
|
| 72 |
+
|
| 73 |
+
# messages = [{"role": msg.role, "content": msg.content} for msg in chat_request.messages]
|
| 74 |
+
|
| 75 |
+
# # Get model info
|
| 76 |
+
# model_info = get_model_info(chat_request.model)
|
| 77 |
+
# if not model_info:
|
| 78 |
+
# return jsonify({'detail': 'Invalid model specified'}), 400
|
| 79 |
+
|
| 80 |
+
# # Model mapping
|
| 81 |
+
# model_mapping = {
|
| 82 |
+
# "meta-llama-405b-turbo": "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
|
| 83 |
+
# "claude-3.5-sonnet": "claude-3-sonnet-20240229",
|
| 84 |
+
# }
|
| 85 |
+
# model_name = model_mapping.get(chat_request.model, chat_request.model)
|
| 86 |
+
# credits_reduction = {
|
| 87 |
+
# "gpt-4o": 1,
|
| 88 |
+
# "claude-3-sonnet-20240229": 1,
|
| 89 |
+
# "gemini-1.5-pro": 1,
|
| 90 |
+
# "gemini-1-5-flash": 1,
|
| 91 |
+
# "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo": 1,
|
| 92 |
+
# "o1-mini": 2,
|
| 93 |
+
# "o1-preview": 3,
|
| 94 |
+
# }.get(model_name, 0)
|
| 95 |
+
|
| 96 |
+
# if chat_request.stream:
|
| 97 |
+
# def generate():
|
| 98 |
+
# try:
|
| 99 |
+
# for chunk in API_Inference(messages, model=model_name, stream=True,
|
| 100 |
+
# max_tokens=chat_request.max_tokens,
|
| 101 |
+
# temperature=chat_request.temperature,
|
| 102 |
+
# top_p=chat_request.top_p):
|
| 103 |
+
# data = json.dumps({'choices': [{'delta': {'content': chunk}}]})
|
| 104 |
+
# yield f"data: {data}\n\n"
|
| 105 |
+
# yield f"data: [DONE]\n\nCredits used: {credits_reduction}\n\n"
|
| 106 |
+
# update_request_count(api_key, credits_reduction)
|
| 107 |
+
# except Exception as e:
|
| 108 |
+
# yield f"data: [ERROR] {str(e)}\n\n"
|
| 109 |
+
|
| 110 |
+
# return Response(generate(), mimetype='text/event-stream')
|
| 111 |
+
# else:
|
| 112 |
+
# response = API_Inference(messages, model=model_name, stream=False,
|
| 113 |
+
# max_tokens=chat_request.max_tokens,
|
| 114 |
+
# temperature=chat_request.temperature,
|
| 115 |
+
# top_p=chat_request.top_p)
|
| 116 |
+
# update_request_count(api_key, credits_reduction)
|
| 117 |
+
# prompt_tokens = sum(len(msg['content'].split()) for msg in messages)
|
| 118 |
+
# completion_tokens = len(response.split())
|
| 119 |
+
# total_tokens = prompt_tokens + completion_tokens
|
| 120 |
+
# return jsonify({
|
| 121 |
+
# "id": f"chatcmpl-{str(uuid.uuid4())}",
|
| 122 |
+
# "object": "chat.completion",
|
| 123 |
+
# "created": int(uuid.uuid1().time // 1e7),
|
| 124 |
+
# "model": model_name,
|
| 125 |
+
# "choices": [
|
| 126 |
+
# {
|
| 127 |
+
# "index": 0,
|
| 128 |
+
# "message": {
|
| 129 |
+
# "role": "assistant",
|
| 130 |
+
# "content": response
|
| 131 |
+
# },
|
| 132 |
+
# "finish_reason": "stop"
|
| 133 |
+
# }
|
| 134 |
+
# ],
|
| 135 |
+
# "usage": {
|
| 136 |
+
# "prompt_tokens": prompt_tokens,
|
| 137 |
+
# "completion_tokens": completion_tokens,
|
| 138 |
+
# "total_tokens": total_tokens
|
| 139 |
+
# },
|
| 140 |
+
# "credits_used": credits_reduction
|
| 141 |
+
# })
|
| 142 |
+
# except Exception as e:
|
| 143 |
+
# return jsonify({'detail': str(e)}), 500
|
| 144 |
|
| 145 |
@app.route('/rate_limit/status', methods=['GET'])
|
| 146 |
@requires_api_key
|