Update app.py
Browse files
app.py
CHANGED
|
@@ -662,36 +662,28 @@ def handsome_chat_completions():
|
|
| 662 |
],
|
| 663 |
}
|
| 664 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
if data.get("stream", False):
|
| 666 |
def generate():
|
| 667 |
yield f"data: {json.dumps(response_data)}\n\n"
|
| 668 |
yield "data: [DONE]\n\n"
|
| 669 |
|
| 670 |
-
logging.info(
|
| 671 |
-
f"使用的key: {api_key}, "
|
| 672 |
-
f"总共用时: {total_time:.4f}秒, "
|
| 673 |
-
f"使用的模型: {model_name}"
|
| 674 |
-
)
|
| 675 |
-
|
| 676 |
-
with data_lock:
|
| 677 |
-
request_timestamps.append(time.time())
|
| 678 |
-
token_counts.append(0) # Image generation doesn't use tokens
|
| 679 |
return Response(
|
| 680 |
stream_with_context(generate()),
|
| 681 |
content_type='text/event-stream'
|
| 682 |
)
|
| 683 |
else:
|
| 684 |
-
logging.info(
|
| 685 |
-
f"使用的key: {api_key}, "
|
| 686 |
-
f"总共用时: {total_time:.4f}秒, "
|
| 687 |
-
f"使用的模型: {model_name}"
|
| 688 |
-
)
|
| 689 |
-
|
| 690 |
-
with data_lock:
|
| 691 |
-
request_timestamps.append(time.time())
|
| 692 |
-
token_counts.append(0) # Image generation doesn't use tokens
|
| 693 |
-
|
| 694 |
return jsonify(response_data)
|
|
|
|
| 695 |
except (KeyError, ValueError, IndexError) as e:
|
| 696 |
logging.error(
|
| 697 |
f"解析响应 JSON 失败: {e}, "
|
|
@@ -713,36 +705,29 @@ def handsome_chat_completions():
|
|
| 713 |
}
|
| 714 |
],
|
| 715 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
if data.get("stream", False):
|
| 717 |
def generate():
|
| 718 |
yield f"data: {json.dumps(response_data)}\n\n"
|
| 719 |
yield "data: [DONE]\n\n"
|
| 720 |
|
| 721 |
-
logging.info(
|
| 722 |
-
f"使用的key: {api_key}, "
|
| 723 |
-
f"总共用时: {total_time:.4f}秒, "
|
| 724 |
-
f"使用的模型: {model_name}"
|
| 725 |
-
)
|
| 726 |
-
|
| 727 |
-
with data_lock:
|
| 728 |
-
request_timestamps.append(time.time())
|
| 729 |
-
token_counts.append(0) # Image generation doesn't use tokens
|
| 730 |
return Response(
|
| 731 |
stream_with_context(generate()),
|
| 732 |
content_type='text/event-stream'
|
| 733 |
)
|
| 734 |
else:
|
| 735 |
-
logging.info(
|
| 736 |
-
f"使用的key: {api_key}, "
|
| 737 |
-
f"总共用时: {total_time:.4f}秒, "
|
| 738 |
-
f"使用的模型: {model_name}"
|
| 739 |
-
)
|
| 740 |
-
|
| 741 |
-
with data_lock:
|
| 742 |
-
request_timestamps.append(time.time())
|
| 743 |
-
token_counts.append(0) # Image generation doesn't use tokens
|
| 744 |
-
|
| 745 |
return jsonify(response_data)
|
|
|
|
| 746 |
except requests.exceptions.RequestException as e:
|
| 747 |
logging.error(f"请求转发异常: {e}")
|
| 748 |
return jsonify({"error": str(e)}), 500
|
|
|
|
| 662 |
],
|
| 663 |
}
|
| 664 |
|
| 665 |
+
logging.info(
|
| 666 |
+
f"使用的key: {api_key}, "
|
| 667 |
+
f"总共用时: {total_time:.4f}秒, "
|
| 668 |
+
f"使用的模型: {model_name}"
|
| 669 |
+
)
|
| 670 |
+
|
| 671 |
+
with data_lock:
|
| 672 |
+
request_timestamps.append(time.time())
|
| 673 |
+
token_counts.append(0) # Image generation doesn't use tokens
|
| 674 |
+
|
| 675 |
if data.get("stream", False):
|
| 676 |
def generate():
|
| 677 |
yield f"data: {json.dumps(response_data)}\n\n"
|
| 678 |
yield "data: [DONE]\n\n"
|
| 679 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
return Response(
|
| 681 |
stream_with_context(generate()),
|
| 682 |
content_type='text/event-stream'
|
| 683 |
)
|
| 684 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
return jsonify(response_data)
|
| 686 |
+
|
| 687 |
except (KeyError, ValueError, IndexError) as e:
|
| 688 |
logging.error(
|
| 689 |
f"解析响应 JSON 失败: {e}, "
|
|
|
|
| 705 |
}
|
| 706 |
],
|
| 707 |
}
|
| 708 |
+
|
| 709 |
+
logging.info(
|
| 710 |
+
f"使用的key: {api_key}, "
|
| 711 |
+
f"总共用时: {total_time:.4f}秒, "
|
| 712 |
+
f"使用的模型: {model_name}"
|
| 713 |
+
)
|
| 714 |
+
|
| 715 |
+
with data_lock:
|
| 716 |
+
request_timestamps.append(time.time())
|
| 717 |
+
token_counts.append(0) # Image generation doesn't use tokens
|
| 718 |
+
|
| 719 |
if data.get("stream", False):
|
| 720 |
def generate():
|
| 721 |
yield f"data: {json.dumps(response_data)}\n\n"
|
| 722 |
yield "data: [DONE]\n\n"
|
| 723 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 724 |
return Response(
|
| 725 |
stream_with_context(generate()),
|
| 726 |
content_type='text/event-stream'
|
| 727 |
)
|
| 728 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
return jsonify(response_data)
|
| 730 |
+
|
| 731 |
except requests.exceptions.RequestException as e:
|
| 732 |
logging.error(f"请求转发异常: {e}")
|
| 733 |
return jsonify({"error": str(e)}), 500
|