Update app.py
Browse files
app.py
CHANGED
|
@@ -549,6 +549,22 @@ async def transform_openai_to_replicate(openai_request: Dict[str, Any], model_ov
|
|
| 549 |
logger.error(f"Error transforming request: {str(e)}")
|
| 550 |
raise HTTPException(status_code=400, detail=f"Request transformation error: {str(e)}")
|
| 551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
async def create_replicate_prediction(session: aiohttp.ClientSession, model: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 553 |
"""创建Replicate预测"""
|
| 554 |
try:
|
|
@@ -559,17 +575,9 @@ async def create_replicate_prediction(session: aiohttp.ClientSession, model: str
|
|
| 559 |
}
|
| 560 |
|
| 561 |
logger.info(f"Creating prediction for model: {model}")
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
if "image" in log_data["input"]:
|
| 566 |
-
image_data = log_data["input"]["image"]
|
| 567 |
-
if image_data.startswith("http"):
|
| 568 |
-
log_data["input"]["image"] = f"[IMAGE_URL: {image_data}]"
|
| 569 |
-
else:
|
| 570 |
-
log_data["input"]["image"] = f"[IMAGE_DATA_{len(image_data)}]"
|
| 571 |
-
if "prompt" in log_data["input"] and len(log_data["input"]["prompt"]) > 1000:
|
| 572 |
-
log_data["input"]["prompt"] = log_data["input"]["prompt"][:1000] + "...[TRUNCATED]"
|
| 573 |
logger.info(f"Request data: {json.dumps(log_data, indent=2)}")
|
| 574 |
|
| 575 |
async with session.post(url, headers=headers, json=data, timeout=30) as response:
|
|
@@ -653,7 +661,7 @@ async def root():
|
|
| 653 |
"status": "running",
|
| 654 |
"replicate_token_configured": bool(REPLICATE_API_TOKEN),
|
| 655 |
"imgbb_token_configured": bool(IMGBB_API_KEY),
|
| 656 |
-
"version": "1.2.
|
| 657 |
"supported_models": list(MODEL_CONFIGS.keys()),
|
| 658 |
"vision_support": True,
|
| 659 |
"file_support": True,
|
|
|
|
| 549 |
logger.error(f"Error transforming request: {str(e)}")
|
| 550 |
raise HTTPException(status_code=400, detail=f"Request transformation error: {str(e)}")
|
| 551 |
|
| 552 |
+
def create_log_safe_data(data: Dict[str, Any]) -> Dict[str, Any]:
|
| 553 |
+
"""创建用于日志记录的安全数据副本,不修改原始数据"""
|
| 554 |
+
log_data = json.loads(json.dumps(data)) # 深拷贝
|
| 555 |
+
|
| 556 |
+
if "input" in log_data:
|
| 557 |
+
if "image" in log_data["input"]:
|
| 558 |
+
image_data = log_data["input"]["image"]
|
| 559 |
+
if image_data.startswith("http"):
|
| 560 |
+
log_data["input"]["image"] = f"[IMAGE_URL: {image_data}]"
|
| 561 |
+
else:
|
| 562 |
+
log_data["input"]["image"] = f"[IMAGE_DATA_{len(image_data)}]"
|
| 563 |
+
if "prompt" in log_data["input"] and len(log_data["input"]["prompt"]) > 1000:
|
| 564 |
+
log_data["input"]["prompt"] = log_data["input"]["prompt"][:1000] + "...[TRUNCATED]"
|
| 565 |
+
|
| 566 |
+
return log_data
|
| 567 |
+
|
| 568 |
async def create_replicate_prediction(session: aiohttp.ClientSession, model: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 569 |
"""创建Replicate预测"""
|
| 570 |
try:
|
|
|
|
| 575 |
}
|
| 576 |
|
| 577 |
logger.info(f"Creating prediction for model: {model}")
|
| 578 |
+
|
| 579 |
+
# 创建用于日志的安全数据副本
|
| 580 |
+
log_data = create_log_safe_data(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
logger.info(f"Request data: {json.dumps(log_data, indent=2)}")
|
| 582 |
|
| 583 |
async with session.post(url, headers=headers, json=data, timeout=30) as response:
|
|
|
|
| 661 |
"status": "running",
|
| 662 |
"replicate_token_configured": bool(REPLICATE_API_TOKEN),
|
| 663 |
"imgbb_token_configured": bool(IMGBB_API_KEY),
|
| 664 |
+
"version": "1.2.2",
|
| 665 |
"supported_models": list(MODEL_CONFIGS.keys()),
|
| 666 |
"vision_support": True,
|
| 667 |
"file_support": True,
|