Update app.py
Browse files
app.py
CHANGED
|
@@ -661,28 +661,6 @@ def handsome_chat_completions():
|
|
| 661 |
}
|
| 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(
|
|
@@ -705,29 +683,18 @@ def handsome_chat_completions():
|
|
| 705 |
}
|
| 706 |
],
|
| 707 |
}
|
| 708 |
-
|
| 709 |
-
logging.info(
|
| 710 |
-
f"使用的key: {api_key}, "
|
| 711 |
-
f"总共用时: {total_time:.4f}秒, "
|
| 712 |
-
f"使用的模型: {model_name}"
|
| 713 |
-
)
|
| 714 |
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 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
|
|
|
|
| 661 |
}
|
| 662 |
],
|
| 663 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
|
| 665 |
except (KeyError, ValueError, IndexError) as e:
|
| 666 |
logging.error(
|
|
|
|
| 683 |
}
|
| 684 |
],
|
| 685 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 686 |
|
| 687 |
+
logging.info(
|
| 688 |
+
f"使用的key: {api_key}, "
|
| 689 |
+
f"总共用时: {total_time:.4f}秒, "
|
| 690 |
+
f"使用的模型: {model_name}"
|
| 691 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
+
with data_lock:
|
| 694 |
+
request_timestamps.append(time.time())
|
| 695 |
+
token_counts.append(0) # Image generation doesn't use tokens
|
| 696 |
+
|
| 697 |
+
return jsonify(response_data)
|
| 698 |
except requests.exceptions.RequestException as e:
|
| 699 |
logging.error(f"请求转发异常: {e}")
|
| 700 |
return jsonify({"error": str(e)}), 500
|