Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -761,30 +761,25 @@ def handle_image_response(image_url):
|
|
761 |
logger.error(str(error), "Server")
|
762 |
return "生图失败,请查看TUMY图床密钥是否设置正确"
|
763 |
|
764 |
-
|
765 |
def handle_non_stream_response(response, model):
|
766 |
try:
|
767 |
-
|
768 |
-
|
|
|
769 |
full_response = ""
|
770 |
|
771 |
CONFIG["IS_THINKING"] = False
|
772 |
CONFIG["IS_IMG_GEN"] = False
|
773 |
CONFIG["IS_IMG_GEN2"] = False
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
for line in lines:
|
778 |
-
if not line.strip():
|
779 |
continue
|
780 |
-
|
781 |
try:
|
782 |
-
line_json = json.loads(
|
783 |
if line_json.get("error"):
|
784 |
logger.error(json.dumps(line_json, indent=2), "Server")
|
785 |
-
|
786 |
-
CONFIG["API"]["TEMP_COOKIE"] = None
|
787 |
-
raise ValueError("RateLimitError")
|
788 |
|
789 |
response_data = line_json.get("result", {}).get("response")
|
790 |
if not response_data:
|
@@ -805,23 +800,21 @@ def handle_non_stream_response(response, model):
|
|
805 |
except json.JSONDecodeError:
|
806 |
continue
|
807 |
except Exception as e:
|
808 |
-
logger.error(f"
|
809 |
continue
|
810 |
-
|
811 |
return full_response
|
812 |
-
|
813 |
except Exception as error:
|
814 |
logger.error(str(error), "Server")
|
815 |
raise
|
816 |
-
|
817 |
def handle_stream_response(response, model):
|
818 |
def generate():
|
819 |
-
|
820 |
|
|
|
821 |
CONFIG["IS_THINKING"] = False
|
822 |
CONFIG["IS_IMG_GEN"] = False
|
823 |
CONFIG["IS_IMG_GEN2"] = False
|
824 |
-
logger.info("开始处理流式响应", "Server")
|
825 |
|
826 |
for chunk in stream:
|
827 |
if not chunk:
|
|
|
761 |
logger.error(str(error), "Server")
|
762 |
return "生图失败,请查看TUMY图床密钥是否设置正确"
|
763 |
|
|
|
764 |
def handle_non_stream_response(response, model):
|
765 |
try:
|
766 |
+
logger.info("开始处理非流式响应", "Server")
|
767 |
+
|
768 |
+
stream = response.iter_lines()
|
769 |
full_response = ""
|
770 |
|
771 |
CONFIG["IS_THINKING"] = False
|
772 |
CONFIG["IS_IMG_GEN"] = False
|
773 |
CONFIG["IS_IMG_GEN2"] = False
|
774 |
+
|
775 |
+
for chunk in stream:
|
776 |
+
if not chunk:
|
|
|
|
|
777 |
continue
|
|
|
778 |
try:
|
779 |
+
line_json = json.loads(chunk.decode("utf-8").strip())
|
780 |
if line_json.get("error"):
|
781 |
logger.error(json.dumps(line_json, indent=2), "Server")
|
782 |
+
return json.dumps({"error": "RateLimitError"}) + "\n\n"
|
|
|
|
|
783 |
|
784 |
response_data = line_json.get("result", {}).get("response")
|
785 |
if not response_data:
|
|
|
800 |
except json.JSONDecodeError:
|
801 |
continue
|
802 |
except Exception as e:
|
803 |
+
logger.error(f"处理流式响应行时出错: {str(e)}", "Server")
|
804 |
continue
|
805 |
+
|
806 |
return full_response
|
|
|
807 |
except Exception as error:
|
808 |
logger.error(str(error), "Server")
|
809 |
raise
|
|
|
810 |
def handle_stream_response(response, model):
|
811 |
def generate():
|
812 |
+
logger.info("开始处理流式响应", "Server")
|
813 |
|
814 |
+
stream = response.iter_lines()
|
815 |
CONFIG["IS_THINKING"] = False
|
816 |
CONFIG["IS_IMG_GEN"] = False
|
817 |
CONFIG["IS_IMG_GEN2"] = False
|
|
|
818 |
|
819 |
for chunk in stream:
|
820 |
if not chunk:
|