Update app.py
Browse files
app.py
CHANGED
@@ -307,20 +307,41 @@ def handsome_chat_completions():
|
|
307 |
return jsonify({"error": "Unauthorized"}), 401
|
308 |
|
309 |
data = request.get_json()
|
310 |
-
logging.info(f"Request data: {data}")
|
311 |
if not data or 'model' not in data:
|
312 |
return jsonify({"error": "Invalid request data"}), 400
|
313 |
if data['model'] not in models["text"] and data['model'] not in models["image"]:
|
314 |
return jsonify({"error": "Invalid model"}), 400
|
315 |
|
316 |
model_name = data['model']
|
317 |
-
|
318 |
request_type = determine_request_type(
|
319 |
model_name,
|
320 |
models["text"] + models["image"],
|
321 |
models["free_text"] + models["free_image"]
|
322 |
)
|
323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
api_key = select_key(request_type, model_name)
|
325 |
|
326 |
if not api_key:
|
@@ -401,7 +422,6 @@ def handsome_chat_completions():
|
|
401 |
# if "prompt_tokens" in response_json["usage"]:
|
402 |
# prompt_tokens += response_json["usage"]["prompt_tokens"]
|
403 |
|
404 |
-
|
405 |
if "choices" in response_json:
|
406 |
for choice in response_json["choices"]:
|
407 |
if "delta" in choice and "content" in choice["delta"]:
|
|
|
307 |
return jsonify({"error": "Unauthorized"}), 401
|
308 |
|
309 |
data = request.get_json()
|
310 |
+
logging.info(f"Request data: {data}")
|
311 |
if not data or 'model' not in data:
|
312 |
return jsonify({"error": "Invalid request data"}), 400
|
313 |
if data['model'] not in models["text"] and data['model'] not in models["image"]:
|
314 |
return jsonify({"error": "Invalid model"}), 400
|
315 |
|
316 |
model_name = data['model']
|
317 |
+
|
318 |
request_type = determine_request_type(
|
319 |
model_name,
|
320 |
models["text"] + models["image"],
|
321 |
models["free_text"] + models["free_image"]
|
322 |
)
|
323 |
|
324 |
+
user_content = extract_user_content(data.get("messages", []))
|
325 |
+
|
326 |
+
if "hi" in user_content.lower() or "hello" in user_content.lower():
|
327 |
+
canned_response = {
|
328 |
+
"choices": [
|
329 |
+
{
|
330 |
+
"message": {
|
331 |
+
"content": "这是公益api,模型全部可用且保真,请不要对模型进行无意义的测试,请尽量不要使用高级模型解决没必要的问题。"
|
332 |
+
},
|
333 |
+
"index": 0,
|
334 |
+
"finish_reason": "stop"
|
335 |
+
}
|
336 |
+
],
|
337 |
+
"usage": {
|
338 |
+
"prompt_tokens": 0,
|
339 |
+
"completion_tokens": 0,
|
340 |
+
"total_tokens": 0
|
341 |
+
}
|
342 |
+
}
|
343 |
+
return jsonify(canned_response)
|
344 |
+
|
345 |
api_key = select_key(request_type, model_name)
|
346 |
|
347 |
if not api_key:
|
|
|
422 |
# if "prompt_tokens" in response_json["usage"]:
|
423 |
# prompt_tokens += response_json["usage"]["prompt_tokens"]
|
424 |
|
|
|
425 |
if "choices" in response_json:
|
426 |
for choice in response_json["choices"]:
|
427 |
if "delta" in choice and "content" in choice["delta"]:
|