From 92006a0d37ed6926966c7674e0b671f32151ca66 Mon Sep 17 00:00:00 2001 From: Netlops Date: Fri, 16 Jan 2026 17:35:56 +0800 Subject: [PATCH] feat(api): support remote image URL downloading in chat completion - Extract image from URL or base64 instead of base64 only - Add support for downloading remote image URLs starting with http/https - Implement error handling for image download failures - Add debug logging for image processing steps fix(config): update model keys for veo_3_0 video generation - Update veo_3_0_r2v_fast_portrait model key to veo_3_0_r2v_fast_portrait_ultra_relaxed - Update veo_3_0_r2v_fast_landscape model key to veo_3_0_r2v_fast_ultra_relaxed --- src/api/routes.py | 14 +++++++++++++- src/services/generation_handler.py | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/api/routes.py b/src/api/routes.py index 1b345b7..e9f4e10 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -111,7 +111,7 @@ async def create_chat_completion( if item.get("type") == "text": prompt = item.get("text", "") elif item.get("type") == "image_url": - # Extract base64 image + # Extract image from URL or base64 image_url = item.get("image_url", {}).get("url", "") if image_url.startswith("data:image"): # Parse base64 @@ -120,6 +120,18 @@ async def create_chat_completion( image_base64 = match.group(1) image_bytes = base64.b64decode(image_base64) images.append(image_bytes) + elif image_url.startswith("http://") or image_url.startswith("https://"): + # Download remote image URL + debug_logger.log_info(f"[IMAGE_URL] 下载远程图片: {image_url}") + try: + downloaded_bytes = await retrieve_image_data(image_url) + if downloaded_bytes and len(downloaded_bytes) > 0: + images.append(downloaded_bytes) + debug_logger.log_info(f"[IMAGE_URL] ✅ 远程图片下载成功: {len(downloaded_bytes)} 字节") + else: + debug_logger.log_warning(f"[IMAGE_URL] ⚠️ 远程图片下载失败或为空: {image_url}") + except Exception as e: + debug_logger.log_error(f"[IMAGE_URL] ❌ 远程图片下载异常: {str(e)}") # Fallback to deprecated image parameter if request.image and not images: diff --git a/src/services/generation_handler.py b/src/services/generation_handler.py index 05964dc..816b292 100644 --- a/src/services/generation_handler.py +++ b/src/services/generation_handler.py @@ -172,7 +172,7 @@ MODEL_CONFIG = { "veo_3_0_r2v_fast_portrait": { "type": "video", "video_type": "r2v", - "model_key": "veo_3_0_r2v_fast", + "model_key": "veo_3_0_r2v_fast_portrait_ultra_relaxed", "aspect_ratio": "VIDEO_ASPECT_RATIO_PORTRAIT", "supports_images": True, "min_images": 0, @@ -181,7 +181,7 @@ MODEL_CONFIG = { "veo_3_0_r2v_fast_landscape": { "type": "video", "video_type": "r2v", - "model_key": "veo_3_0_r2v_fast", + "model_key": "veo_3_0_r2v_fast_ultra_relaxed", "aspect_ratio": "VIDEO_ASPECT_RATIO_LANDSCAPE", "supports_images": True, "min_images": 0,