Update app.py
Browse files
app.py
CHANGED
@@ -324,23 +324,45 @@ def handsome_chat_completions():
|
|
324 |
user_content = extract_user_content(data.get("messages", []))
|
325 |
|
326 |
if "hi" in user_content.lower() or "hello" in user_content.lower():
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
}
|
342 |
-
|
343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
api_key = select_key(request_type, model_name)
|
346 |
|
@@ -534,6 +556,7 @@ def handsome_chat_completions():
|
|
534 |
logging.error(f"请求转发异常: {e}")
|
535 |
return jsonify({"error": str(e)}), 500
|
536 |
|
|
|
537 |
if __name__ == '__main__':
|
538 |
logging.info(f"环境变量:{os.environ}")
|
539 |
|
|
|
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_content = "这是公益api,模型全部可用且保真,请不要对模型进行无意义的测试,请尽量不要使用高级模型解决没必要的问题。"
|
328 |
+
|
329 |
+
if data.get("stream", False):
|
330 |
+
def generate_canned_stream():
|
331 |
+
message_data = {
|
332 |
+
"choices": [
|
333 |
+
{
|
334 |
+
"delta": {
|
335 |
+
"content": canned_response_content
|
336 |
+
},
|
337 |
+
"index": 0,
|
338 |
+
"finish_reason": "stop"
|
339 |
+
}
|
340 |
+
]
|
341 |
}
|
342 |
+
yield f"data: {json.dumps(message_data)}\n\n".encode("utf-8")
|
343 |
+
yield f"data: [DONE]\n\n".encode("utf-8")
|
344 |
+
return Response(
|
345 |
+
stream_with_context(generate_canned_stream()),
|
346 |
+
content_type="text/event-stream"
|
347 |
+
)
|
348 |
+
else:
|
349 |
+
canned_response = {
|
350 |
+
"choices": [
|
351 |
+
{
|
352 |
+
"message": {
|
353 |
+
"content": canned_response_content
|
354 |
+
},
|
355 |
+
"index": 0,
|
356 |
+
"finish_reason": "stop"
|
357 |
+
}
|
358 |
+
],
|
359 |
+
"usage": {
|
360 |
+
"prompt_tokens": 0,
|
361 |
+
"completion_tokens": 0,
|
362 |
+
"total_tokens": 0
|
363 |
+
}
|
364 |
+
}
|
365 |
+
return jsonify(canned_response)
|
366 |
|
367 |
api_key = select_key(request_type, model_name)
|
368 |
|
|
|
556 |
logging.error(f"请求转发异常: {e}")
|
557 |
return jsonify({"error": str(e)}), 500
|
558 |
|
559 |
+
|
560 |
if __name__ == '__main__':
|
561 |
logging.info(f"环境变量:{os.environ}")
|
562 |
|