Spaces:
Sleeping
Sleeping
Update app.py
Browse files760 unmodified lines76176276376476576676776876977077177277377477577677777877978078178278378478578678778878979014 unmodified lines805806807808809810811812813814815816817818819820821822823824825826827760 unmodified lineslogger.error(str(error), "Server")return "生图失败,请查看TUMY图床密钥是否设置正确"def handle_non_stream_response(response, model):try:content = response.textlines = content.split('\n')full_response = ""CONFIG["IS_THINKING"] = FalseCONFIG["IS_IMG_GEN"] = FalseCONFIG["IS_IMG_GEN2"] = Falselogger.info("开始处理非流式响应", "Server")for line in lines:if not line.strip():continuetry:line_json = json.loads(line.strip())if line_json.get("error"):logger.error(json.dumps(line_json, indent=2), "Server")if line_json.get("error", {}).get("name") == "RateLimitError":CONFIG["API"]["TEMP_COOKIE"] = Noneraise ValueError("RateLimitError")response_data = line_json.get("result", {}).get("response")if not response_data:14 unmodified linesexcept json.JSONDecodeError:continueexcept Exception as e:logger.error(f"处理响应行时出错: {str(e)}", "Server")continuereturn full_responseexcept Exception as error:logger.error(str(error), "Server")raisedef handle_stream_response(response, model):def generate():stream = response.iter_lines()CONFIG["IS_THINKING"] = FalseCONFIG["IS_IMG_GEN"] = FalseCONFIG["IS_IMG_GEN2"] = Falselogger.info("开始处理流式响应", "Server")for chunk in stream:if not chunk:760 unmodified lines76176276376476576676776876977077177277377477577677777877978078178278378478514 unmodified lines800801802803804805806807808809810811812813814815816817818819820760 unmodified lineslogger.error(str(error), "Server")return "生图失败,请查看TUMY图床密钥是否设置正确"def handle_non_stream_response(response, model):try:logger.info("开始处理非流式响应", "Server")stream = response.iter_lines()full_response = ""CONFIG["IS_THINKING"] = FalseCONFIG["IS_IMG_GEN"] = FalseCONFIG["IS_IMG_GEN2"] = Falsefor chunk in stream:if not chunk:continuetry:line_json = json.loads(chunk.decode("utf-8").strip())if line_json.get("error"):logger.error(json.dumps(line_json, indent=2), "Server")return json.dumps({"error": "RateLimitError"}) + "\n\n"response_data = line_json.get("result", {}).get("response")if not response_data:14 unmodified linesexcept json.JSONDecodeError:continueexcept Exception as e:logger.error(f"处理流式响应行时出错: {str(e)}", "Server")continuereturn full_responseexcept Exception as error:logger.error(str(error), "Server")raisedef handle_stream_response(response, model):def generate():logger.info("开始处理流式响应", "Server")stream = response.iter_lines()CONFIG["IS_THINKING"] = FalseCONFIG["IS_IMG_GEN"] = FalseCONFIG["IS_IMG_GEN2"] = Falsefor chunk in stream:if not chunk:
app.py+12-19