新增 MiniMax H3 Highspeed/Lite 与 Seedance 2.5 Flash,兼容视频参数和旧工作流
This commit is contained in:
+107
-3
@@ -6,6 +6,7 @@ import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from inspect import signature
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, call, patch
|
||||
|
||||
import av
|
||||
@@ -18,11 +19,17 @@ PLUGIN_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
CUSTOM_NODES_DIR = os.path.dirname(PLUGIN_DIR)
|
||||
COMFY_ROOT = os.environ.get(
|
||||
"COMFYUI_ROOT",
|
||||
r"F:\ComfyUI_windows_portable\ComfyUI",
|
||||
str(Path(__file__).resolve().parents[3]),
|
||||
)
|
||||
sys.path.insert(0, COMFY_ROOT)
|
||||
sys.path.insert(0, CUSTOM_NODES_DIR)
|
||||
|
||||
# The portable CPU build must not attempt CUDA initialization during imports.
|
||||
from comfy.cli_args import args # noqa: E402
|
||||
|
||||
if torch.version.cuda is None:
|
||||
args.cpu = True
|
||||
|
||||
from comfyui_o1key.clients.minimax_h3_client import ( # noqa: E402
|
||||
FAILURE_STATUSES,
|
||||
MiniMaxH3Client,
|
||||
@@ -34,11 +41,14 @@ from comfyui_o1key.clients.minimax_h3_client import ( # noqa: E402
|
||||
from comfyui_o1key.clients.newapi_veo_client import NewAPIVeoClient # noqa: E402
|
||||
from comfyui_o1key.nodes.minimax_h3_video import ( # noqa: E402
|
||||
MAX_SEED,
|
||||
MODEL_HIGHSPEED_ID,
|
||||
MODEL_LITE_ID,
|
||||
MODEL_MAX_ID,
|
||||
MODE_FIRST,
|
||||
MODE_FIRST_LAST,
|
||||
MODE_LAST,
|
||||
MODE_REFERENCE,
|
||||
LEGACY_MODE_REFERENCE,
|
||||
MODE_TEXT,
|
||||
MiniMaxH3Video,
|
||||
_make_progress_callbacks,
|
||||
@@ -56,6 +66,81 @@ from comfyui_o1key.utils.video_task import POLL_DEADLINE_SECONDS # noqa: E402
|
||||
|
||||
|
||||
class MiniMaxH3PayloadTests(unittest.TestCase):
|
||||
def test_legacy_reference_mode_builds_the_same_multimodal_payload(self):
|
||||
parameters = dict(
|
||||
prompt="Follow the reference.", resolution="768P", duration=4,
|
||||
reference_image_urls=["https://cdn.example.com/image.png"],
|
||||
)
|
||||
self.assertEqual(
|
||||
build_request_body(mode=LEGACY_MODE_REFERENCE, **parameters),
|
||||
build_request_body(mode=MODE_REFERENCE, **parameters),
|
||||
)
|
||||
|
||||
def test_highspeed_and_lite_limits_and_reference_roles(self):
|
||||
for model in (MODEL_HIGHSPEED_ID, MODEL_LITE_ID):
|
||||
for resolution in ("480P", "768P"):
|
||||
for duration in (4, 15):
|
||||
with self.subTest(model=model, resolution=resolution, duration=duration):
|
||||
body = build_request_body(
|
||||
prompt="A red ball rolls slowly.", model=model,
|
||||
resolution=resolution, duration=duration,
|
||||
mode=MODE_TEXT, ratio="16:9", seed=42,
|
||||
)
|
||||
self.assertEqual(body["model"], model)
|
||||
self.assertEqual(body["seed"], 42)
|
||||
for resolution, duration in (("2K", 4), ("1080P", 4), ("480P", 3), ("480P", 16)):
|
||||
with self.subTest(model=model, resolution=resolution, duration=duration):
|
||||
with self.assertRaises(ValueError):
|
||||
build_request_body(
|
||||
prompt="x", model=model, resolution=resolution,
|
||||
duration=duration, mode=MODE_TEXT, ratio="16:9",
|
||||
)
|
||||
body = build_request_body(
|
||||
prompt="Follow the references.", model=model, resolution="480P",
|
||||
duration=4, mode=MODE_REFERENCE, ratio="9:16",
|
||||
reference_image_urls=["https://cdn.example.com/image.png"],
|
||||
reference_video_urls=["https://cdn.example.com/video.mp4"],
|
||||
reference_audio_urls=["https://cdn.example.com/audio.wav"],
|
||||
)
|
||||
self.assertEqual(body["ratio"], "9:16")
|
||||
self.assertEqual([item["role"] for item in body["content"][1:]],
|
||||
["reference_image", "reference_video", "reference_audio"])
|
||||
|
||||
def test_lite_reference_requires_explicit_fixed_ratio(self):
|
||||
for ratio in (None, "", "adaptive", "2:1"):
|
||||
with self.subTest(ratio=ratio), self.assertRaisesRegex(ValueError, "具体宽高比"):
|
||||
build_request_body(
|
||||
prompt="x", model=MODEL_LITE_ID, resolution="480P", duration=4,
|
||||
mode=MODE_REFERENCE, ratio=ratio,
|
||||
reference_image_urls=["https://cdn.example.com/image.png"],
|
||||
)
|
||||
body = build_request_body(
|
||||
prompt="x", model=MODEL_HIGHSPEED_ID, resolution="480P", duration=4,
|
||||
mode=MODE_REFERENCE,
|
||||
reference_image_urls=["https://cdn.example.com/image.png"],
|
||||
)
|
||||
self.assertEqual(body["ratio"], "adaptive")
|
||||
|
||||
def test_new_models_frame_modes_and_tail_requires_first_frame(self):
|
||||
for model in (MODEL_HIGHSPEED_ID, MODEL_LITE_ID):
|
||||
for mode, frames in (
|
||||
(MODE_FIRST, {"first_url": "https://cdn.example.com/first.png"}),
|
||||
(MODE_FIRST_LAST, {"first_url": "https://cdn.example.com/first.png",
|
||||
"last_url": "https://cdn.example.com/last.png"}),
|
||||
):
|
||||
with self.subTest(model=model, mode=mode):
|
||||
body = build_request_body(
|
||||
prompt="x", model=model, resolution="480P", duration=4,
|
||||
mode=mode, **frames,
|
||||
)
|
||||
self.assertEqual(body["ratio"], "adaptive")
|
||||
self.assertEqual(body["content"][1]["role"], "first_frame")
|
||||
with self.assertRaisesRegex(ValueError, "同时提供首帧"):
|
||||
build_request_body(
|
||||
prompt="x", model=model, resolution="480P", duration=4,
|
||||
mode=MODE_LAST, last_url="https://cdn.example.com/last.png",
|
||||
)
|
||||
|
||||
def test_text_to_video_payload(self):
|
||||
body = build_request_body(
|
||||
prompt="月球上的宇航员",
|
||||
@@ -378,10 +463,15 @@ class MiniMaxH3ClientTests(unittest.TestCase):
|
||||
schema.validate()
|
||||
self.assertIsNotNone(schema)
|
||||
self.assertEqual(
|
||||
[item.id for item in schema.inputs[-2:]],
|
||||
["模型", "seed"],
|
||||
[item.id for item in schema.inputs],
|
||||
["提示词", "模型", "生成模式", "分辨率", "时长", "seed"],
|
||||
)
|
||||
seed_input = schema.inputs[-1]
|
||||
self.assertEqual(schema.inputs[1].options,
|
||||
["MiniMax-H3", "MiniMax-H3-MAX", MODEL_HIGHSPEED_ID, MODEL_LITE_ID])
|
||||
mode_options = [option.key for option in schema.inputs[2].options]
|
||||
self.assertEqual(mode_options[0], "多模态生视频")
|
||||
self.assertNotIn(LEGACY_MODE_REFERENCE, mode_options)
|
||||
self.assertEqual(seed_input.default, 0)
|
||||
self.assertEqual(seed_input.min, 0)
|
||||
self.assertEqual(seed_input.max, MAX_SEED)
|
||||
@@ -411,6 +501,20 @@ class MiniMaxH3ClientTests(unittest.TestCase):
|
||||
|
||||
|
||||
class MiniMaxH3PollingTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_lite_invalid_ratio_is_rejected_before_upload_or_paid_request(self):
|
||||
with (
|
||||
patch("comfyui_o1key.nodes.minimax_h3_video.upload_image", new_callable=AsyncMock) as upload,
|
||||
patch("comfyui_o1key.nodes.minimax_h3_video.MiniMaxH3Client") as client,
|
||||
):
|
||||
with self.assertRaisesRegex(ValueError, "具体宽高比"):
|
||||
await MiniMaxH3Video.execute(
|
||||
提示词="x", 生成模式={"生成模式": LEGACY_MODE_REFERENCE, "宽高比": "adaptive",
|
||||
"参考图片": object()},
|
||||
分辨率="480P", 时长=4, 模型=MODEL_LITE_ID,
|
||||
)
|
||||
upload.assert_not_awaited()
|
||||
client.assert_not_called()
|
||||
|
||||
@staticmethod
|
||||
def _response(payload):
|
||||
response = AsyncMock()
|
||||
|
||||
Reference in New Issue
Block a user