mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix: route img2video endpoint based on mapped params
The get_complete_url method was checking litellm_params for init_image, but that param lives in video_create_optional_request_params after mapping. Fixed by moving endpoint routing to transform_video_create_request where the mapped params are available. Added test to verify auto-routing to img2video when init_image is present.
This commit is contained in:
parent
110f6241ce
commit
91ef877761
2 changed files with 43 additions and 3 deletions
|
|
@ -131,9 +131,8 @@ class ModelsLabVideoConfig(BaseVideoConfig):
|
|||
) -> str:
|
||||
if api_base:
|
||||
return api_base.rstrip("/")
|
||||
# Use img2video if init_image is present in litellm_params
|
||||
if litellm_params.get("init_image") or litellm_params.get("input_reference"):
|
||||
return f"{MODELSLAB_VIDEO_BASE_URL}/img2video"
|
||||
# Default to text2video; endpoint selection is handled in
|
||||
# transform_video_create_request based on mapped params
|
||||
return f"{MODELSLAB_VIDEO_BASE_URL}/text2video"
|
||||
|
||||
def transform_video_create_request(
|
||||
|
|
@ -152,6 +151,10 @@ class ModelsLabVideoConfig(BaseVideoConfig):
|
|||
}
|
||||
request_data.update(video_create_optional_request_params)
|
||||
|
||||
# Route to img2video endpoint if init_image is present
|
||||
if "init_image" in video_create_optional_request_params:
|
||||
api_base = f"{MODELSLAB_VIDEO_BASE_URL}/img2video"
|
||||
|
||||
files_list: List[Tuple[str, Any]] = []
|
||||
return request_data, files_list, api_base
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,43 @@ class TestModelsLabVideoTransformation:
|
|||
assert data["init_image"] == "https://example.com/frame.jpg"
|
||||
assert "img2video" in url
|
||||
|
||||
def test_transform_video_create_request_img2video_auto_route(self):
|
||||
"""When init_image is present, endpoint is auto-routed to img2video."""
|
||||
# Start with text2video base URL (what get_complete_url returns by default)
|
||||
base_url = "https://modelslab.com/api/v6/video/text2video"
|
||||
|
||||
data, files, url = self.config.transform_video_create_request(
|
||||
model="stable-video-diffusion",
|
||||
prompt="Camera panning right",
|
||||
api_base=base_url,
|
||||
video_create_optional_request_params={"init_image": "https://example.com/frame.jpg"},
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert data["key"] == "test-api-key"
|
||||
assert data["init_image"] == "https://example.com/frame.jpg"
|
||||
# Should auto-route to img2video
|
||||
assert "img2video" in url
|
||||
assert "text2video" not in url
|
||||
|
||||
def test_transform_video_create_request_text2video_no_routing(self):
|
||||
"""When no init_image, stays on text2video endpoint."""
|
||||
base_url = "https://modelslab.com/api/v6/video/text2video"
|
||||
|
||||
data, files, url = self.config.transform_video_create_request(
|
||||
model="i2vgen-xl",
|
||||
prompt="A flowing river",
|
||||
api_base=base_url,
|
||||
video_create_optional_request_params={},
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert data["key"] == "test-api-key"
|
||||
# Should stay on text2video
|
||||
assert "text2video" in url
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# transform_video_create_response
|
||||
# -------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue