Skip to content

Commit d4426f6

Browse files
committed
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.
1 parent 53773cd commit d4426f6

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

tests/contracts/test_jimeng_video.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,26 @@ def test_seed_accepts_zero_and_positive(self):
378378
schema = JimengVideo().input_schema
379379
for valid in [0, 1, 42, 999999]:
380380
jsonschema.validate({"prompt": "test", "seed": valid}, schema)
381+
382+
383+
# ------------------------------------------------------------------
384+
# Selector duration → frames mapping
385+
# ------------------------------------------------------------------
386+
387+
class TestSelectorDurationMapping:
388+
389+
def test_duration_5_maps_to_121_frames(self):
390+
payload = JimengVideo._build_payload({"prompt": "x", "duration": 5})
391+
assert payload["frames"] == 121
392+
393+
def test_duration_10_maps_to_241_frames(self):
394+
payload = JimengVideo._build_payload({"prompt": "x", "duration": 10})
395+
assert payload["frames"] == 241
396+
397+
def test_duration_defaults_to_5_when_absent(self):
398+
payload = JimengVideo._build_payload({"prompt": "x"})
399+
assert payload["frames"] == 121
400+
401+
def test_frames_takes_priority_over_duration(self):
402+
payload = JimengVideo._build_payload({"prompt": "x", "frames": 241, "duration": 5})
403+
assert payload["frames"] == 241

tools/video/jimeng_video.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class JimengVideo(BaseTool):
5757
determinism = Determinism.STOCHASTIC
5858
runtime = ToolRuntime.API
5959

60-
dependencies = []
60+
dependencies = ["env:VOLC_ACCESSKEY", "env:VOLC_SECRETKEY"]
6161
install_instructions = (
6262
"Set VOLC_ACCESSKEY and VOLC_SECRETKEY to your Volcengine IAM credentials.\n"
6363
" Get them at https://console.volcengine.com/iam/keymanage\n"
@@ -252,13 +252,22 @@ def _generate(self, inputs: dict[str, Any], *, ak: str, sk: str) -> ToolResult:
252252
model=_REQ_KEY_VIDEO,
253253
)
254254

255+
@staticmethod
256+
def _duration_to_frames(duration: int) -> int:
257+
if duration >= 10:
258+
return 241
259+
return 121
260+
255261
@staticmethod
256262
def _build_payload(inputs: dict[str, Any]) -> dict[str, Any]:
257263
operation = inputs.get("operation", "text_to_video")
264+
frames = inputs.get("frames")
265+
if frames is None:
266+
frames = JimengVideo._duration_to_frames(int(inputs.get("duration", 5)))
258267
payload: dict[str, Any] = {
259268
"req_key": _REQ_KEY_VIDEO,
260269
"prompt": inputs["prompt"],
261-
"frames": int(inputs.get("frames", 121)),
270+
"frames": int(frames),
262271
"aspect_ratio": inputs.get("aspect_ratio", "16:9"),
263272
"seed": int(inputs.get("seed", -1)),
264273
}

0 commit comments

Comments
 (0)