From d4426f6e94cb3dff8106081d9f886d789ab098a0 Mon Sep 17 00:00:00 2001 From: Yiyabo Date: Thu, 23 Jul 2026 01:33:36 +0800 Subject: [PATCH] fix: declare env dependencies and map selector duration to frames - Add env:VOLC_ACCESSKEY and env:VOLC_SECRETKEY to dependencies - Map selector 'duration' (seconds) to Jimeng 'frames' (121/241) - Add 4 selector duration mapping regression tests - 59 tests pass Fixes calesthio's third review feedback on PR #341. --- tests/contracts/test_jimeng_video.py | 23 +++++++++++++++++++++++ tools/video/jimeng_video.py | 13 +++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/contracts/test_jimeng_video.py b/tests/contracts/test_jimeng_video.py index 5d060dba..56236c18 100644 --- a/tests/contracts/test_jimeng_video.py +++ b/tests/contracts/test_jimeng_video.py @@ -378,3 +378,26 @@ class TestSchemaValidation: schema = JimengVideo().input_schema for valid in [0, 1, 42, 999999]: jsonschema.validate({"prompt": "test", "seed": valid}, schema) + + +# ------------------------------------------------------------------ +# Selector duration → frames mapping +# ------------------------------------------------------------------ + +class TestSelectorDurationMapping: + + def test_duration_5_maps_to_121_frames(self): + payload = JimengVideo._build_payload({"prompt": "x", "duration": 5}) + assert payload["frames"] == 121 + + def test_duration_10_maps_to_241_frames(self): + payload = JimengVideo._build_payload({"prompt": "x", "duration": 10}) + assert payload["frames"] == 241 + + def test_duration_defaults_to_5_when_absent(self): + payload = JimengVideo._build_payload({"prompt": "x"}) + assert payload["frames"] == 121 + + def test_frames_takes_priority_over_duration(self): + payload = JimengVideo._build_payload({"prompt": "x", "frames": 241, "duration": 5}) + assert payload["frames"] == 241 diff --git a/tools/video/jimeng_video.py b/tools/video/jimeng_video.py index 9410b864..9000054e 100644 --- a/tools/video/jimeng_video.py +++ b/tools/video/jimeng_video.py @@ -57,7 +57,7 @@ class JimengVideo(BaseTool): determinism = Determinism.STOCHASTIC runtime = ToolRuntime.API - dependencies = [] + dependencies = ["env:VOLC_ACCESSKEY", "env:VOLC_SECRETKEY"] install_instructions = ( "Set VOLC_ACCESSKEY and VOLC_SECRETKEY to your Volcengine IAM credentials.\n" " Get them at https://console.volcengine.com/iam/keymanage\n" @@ -252,13 +252,22 @@ class JimengVideo(BaseTool): model=_REQ_KEY_VIDEO, ) + @staticmethod + def _duration_to_frames(duration: int) -> int: + if duration >= 10: + return 241 + return 121 + @staticmethod def _build_payload(inputs: dict[str, Any]) -> dict[str, Any]: operation = inputs.get("operation", "text_to_video") + frames = inputs.get("frames") + if frames is None: + frames = JimengVideo._duration_to_frames(int(inputs.get("duration", 5))) payload: dict[str, Any] = { "req_key": _REQ_KEY_VIDEO, "prompt": inputs["prompt"], - "frames": int(inputs.get("frames", 121)), + "frames": int(frames), "aspect_ratio": inputs.get("aspect_ratio", "16:9"), "seed": int(inputs.get("seed", -1)), }