Add MJ image node, GIF save, and Kling/image generator updates

Ship o1key MJ图片生成 with content/style refs and prompt flags, save-GIF with preview, Kling 4.0 helpers, plus GPT/unified image node polish and docs.
This commit is contained in:
Jony
2026-11-09 09:11:12 +08:00
parent ff1cf830fa
commit a181cc1768
40 changed files with 6711 additions and 675 deletions
+150 -19
View File
@@ -20,6 +20,20 @@ COMFY_ROOT = os.path.dirname(CUSTOM_NODES_DIR)
sys.path.insert(0, COMFY_ROOT)
sys.path.insert(0, CUSTOM_NODES_DIR)
import types as _types
# Avoid package-wide node registry (CUDA probe) in the portable CPU torch build.
_plugin = _types.ModuleType("comfyui_o1key")
_plugin.__path__ = [PLUGIN_DIR]
sys.modules["comfyui_o1key"] = _plugin
for _child in ("nodes", "utils", "clients"):
_mod = _types.ModuleType(f"comfyui_o1key.{_child}")
_mod.__path__ = [os.path.join(PLUGIN_DIR, _child)]
sys.modules[_mod.__name__] = _mod
_model_management = _types.ModuleType("comfy.model_management")
_model_management.processing_interrupted = lambda: False
_model_management.InterruptProcessingException = RuntimeError
sys.modules[_model_management.__name__] = _model_management
from comfy_api.latest import io # noqa: E402
from comfyui_o1key.clients.gpt_image_client import GptImageClient # noqa: E402
from comfyui_o1key.nodes.o1key_image_generator import ( # noqa: E402
@@ -29,9 +43,11 @@ from comfyui_o1key.nodes.o1key_image_generator import ( # noqa: E402
_parse_upload_manifest,
)
from comfyui_o1key.utils.image_utils import ( # noqa: E402
IMAGE_BATCH_MODE_ALIASES,
IMAGE_BATCH_MODE_CARTESIAN,
IMAGE_BATCH_MODE_GROUP_TO_MODELS,
IMAGE_BATCH_MODE_SINGLE_REFERENCES,
IMAGE_BATCH_MODES,
expand_image_generation_tasks,
pil_to_tensor,
tensor_to_pil,
@@ -55,15 +71,24 @@ class O1keyImageGeneratorTests(unittest.TestCase):
"Nano Banana 2.1",
"Nano Banana 2",
"Nano Banana Pro",
"gpt-image-2",
"gpt-image-2.6-sunburst",
"gpt-image-2.6-flare",
"gpt-image-2.5-sunburst",
"gpt-image-2.5-flare",
"gpt-image-2",
"Seedream 5.0 Pro",
"Nano Banana 2 Lite",
"Nano Banana",
],
)
schema = O1keyImageGenerator.define_schema()
complexity_input = next(item for item in schema.inputs if item.id == "复杂度")
self.assertEqual(list(complexity_input.options), ["高", "中", "低"])
self.assertEqual(complexity_input.default, "高")
quality_input = next(item for item in schema.inputs if item.id == "质量")
self.assertEqual(list(quality_input.options)[-2:], ["超高", "最高"])
format_input = next(item for item in schema.inputs if item.id == "输出格式")
self.assertEqual(list(format_input.options), ["jpeg", "png", "webp", "svg", "gif"])
def test_schema_is_panel_node_with_image_output(self):
schema = O1keyImageGenerator.define_schema()
schema.validate()
@@ -91,7 +116,7 @@ class O1keyImageGeneratorTests(unittest.TestCase):
"宽高比", "生图数量", "seed", "参考图清单",
"质量", "输出格式", "蒙版清单", "缩放图片", "背景",
"批量出图", "批量模式", "模特图清单",
"命名规则", "filename_prefix", "格式", "保存位置", "在线搜索", "图层拆分",
"命名规则", "filename_prefix", "格式", "保存位置", "图层拆分", "复杂度", "帧数", "帧时长ms",
],
)
count_input = next(item for item in schema.inputs if item.id == "生图数量")
@@ -100,21 +125,25 @@ class O1keyImageGeneratorTests(unittest.TestCase):
model_input = next(item for item in schema.inputs if item.id == "模型")
self.assertEqual(model_input.default, "Nano Banana 2.1")
self.assertIn("gpt-image-2", model_input.options)
self.assertIn("gpt-image-2.6-sunburst", model_input.options)
self.assertIn("gpt-image-2.6-flare", model_input.options)
self.assertIn("gpt-image-2.5-sunburst", model_input.options)
self.assertIn("gpt-image-2.5-flare", model_input.options)
self.assertIn("Seedream 5.0 Pro", model_input.options)
self.assertNotIn("Nano Banana 2 Lite", model_input.options)
self.assertNotIn("Nano Banana", model_input.options)
thinking_input = next(item for item in schema.inputs if item.id == "思考等级")
self.assertEqual(thinking_input.options, ["低", "高"])
self.assertEqual(thinking_input.default, "低")
self.assertEqual(thinking_input.default, "高")
resolution_input = next(item for item in schema.inputs if item.id == "分辨率")
self.assertEqual(resolution_input.options[0], "智能")
self.assertEqual(resolution_input.default, "智能")
resize_input = next(item for item in schema.inputs if item.id == "缩放图片")
self.assertEqual(resize_input.options, ["不缩放", "智能缩放"])
self.assertEqual(resize_input.default, "不缩放")
self.assertEqual(resize_input.default, "智能缩放")
self.assertNotIn("色彩纠正", [item.id for item in schema.inputs])
format_input = next(item for item in schema.inputs if item.id == "输出格式")
self.assertEqual(format_input.options, ["jpeg", "png", "webp"])
self.assertEqual(format_input.options, ["jpeg", "png", "webp", "svg", "gif"])
self.assertEqual(format_input.default, "jpeg")
background_input = next(item for item in schema.inputs if item.id == "背景")
self.assertEqual(background_input.options, ["auto", "transparent", "opaque"])
@@ -122,6 +151,8 @@ class O1keyImageGeneratorTests(unittest.TestCase):
self.assertNotIn("内容审查强度", [item.id for item in schema.inputs])
quality_input = next(item for item in schema.inputs if item.id == "质量")
self.assertEqual(quality_input.options[-2:], ["超高", "最高"])
seed_input = next(item for item in schema.inputs if item.id == "seed")
self.assertEqual(seed_input.display_name, "种子")
prompt_input = next(item for item in schema.inputs if item.id == "prompt")
self.assertEqual(prompt_input.display_name, "提示词")
self.assertTrue(prompt_input.socketless)
@@ -150,9 +181,7 @@ class O1keyImageGeneratorTests(unittest.TestCase):
self.assertEqual(save_format_input.default, "原始")
location_input = next(item for item in schema.inputs if item.id == "保存位置")
self.assertEqual(location_input.default, "")
search_input = next(item for item in schema.inputs if item.id == "在线搜索")
self.assertEqual(search_input.options, ["关闭", "打开"])
self.assertEqual(search_input.default, "关闭")
self.assertNotIn("在线搜索", [item.id for item in schema.inputs])
def test_batch_task_expansion_covers_group_and_cartesian_pairing(self):
grouped = expand_image_generation_tasks(
@@ -213,6 +242,39 @@ class O1keyImageGeneratorTests(unittest.TestCase):
self.assertEqual(len(fifty_single_references), 50)
self.assertEqual(fifty_single_references[-1]["reference_indices"], (49,))
def test_retired_batch_mode_labels_keep_their_pairing(self):
# Labels shipped before the rename must expand exactly like the current ones.
self.assertEqual(len(IMAGE_BATCH_MODE_ALIASES), 3)
for retired, current in IMAGE_BATCH_MODE_ALIASES.items():
with self.subTest(retired=retired):
retired_tasks = expand_image_generation_tasks(
"套用",
2,
batch_enabled=True,
batch_mode=retired,
reference_count=3,
model_reference_count=4,
)
current_tasks = expand_image_generation_tasks(
"套用",
2,
batch_enabled=True,
batch_mode=current,
reference_count=3,
model_reference_count=4,
)
self.assertEqual(retired_tasks, current_tasks)
def test_batch_mode_labels_are_industry_neutral(self):
self.assertEqual(
IMAGE_BATCH_MODES,
(
"整组素材→多个目标",
"每张素材×每张目标",
"每张素材单独出图",
),
)
def test_reference_limit_is_ten(self):
accepted = [
{"name": f"{index}.png", "subfolder": "", "type": "input"}
@@ -341,7 +403,6 @@ class O1keyImageGeneratorTests(unittest.TestCase):
seed=42,
参考图清单="[]",
缩放图片="智能缩放",
在线搜索="打开",
))
self.assertIs(result[0], image)
@@ -350,10 +411,10 @@ class O1keyImageGeneratorTests(unittest.TestCase):
self.assertEqual(execute.call_args.kwargs["生图数量"], 2)
self.assertEqual(execute.call_args.kwargs["参考图组"], {})
self.assertEqual(execute.call_args.kwargs["缩放图片"], "智能缩放")
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], True)
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], False)
self.assertIs(execute.call_args.kwargs["_o1key_unlimited_downloads"], True)
def test_online_search_is_ignored_for_other_models(self):
def test_google_search_is_never_requested(self):
image = torch.zeros((1, 8, 8, 3), dtype=torch.float32)
with patch(
"comfyui_o1key.nodes.o1key_image_generator.NanoBanana.execute",
@@ -363,12 +424,11 @@ class O1keyImageGeneratorTests(unittest.TestCase):
prompt="一只宇航猫",
模型="Nano Banana Pro",
分辨率="2K",
在线搜索="打开",
))
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], False)
def test_default_model_delegates_nano_banana_21_with_search_and_thinking(self):
def test_default_model_delegates_nano_banana_21_with_thinking(self):
image = torch.zeros((1, 8, 8, 3), dtype=torch.float32)
with patch(
"comfyui_o1key.nodes.o1key_image_generator.NanoBanana.execute",
@@ -376,13 +436,13 @@ class O1keyImageGeneratorTests(unittest.TestCase):
) as execute:
result = asyncio.run(O1keyImageGenerator.execute(
prompt="test", 模型线路="直连", 思考等级="高",
分辨率="4K", 宽高比="1:8", 在线搜索="打开",
分辨率="4K", 宽高比="1:8",
))
self.assertIs(result[0], image)
self.assertEqual(execute.call_args.kwargs["模型"], "Nano Banana 2.1")
self.assertEqual(execute.call_args.kwargs["模型线路"], "直连")
self.assertEqual(execute.call_args.kwargs["思考等级"], "高")
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], True)
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], False)
def test_error_wrappers_apply_to_every_model_family(self):
raw = (
@@ -491,22 +551,24 @@ class O1keyImageGeneratorTests(unittest.TestCase):
):
result = asyncio.run(O1keyImageGenerator.execute(
prompt="一只宇航猫",
模型="gpt-image-2.5-sunburst",
模型="gpt-image-2.6-sunburst",
模型线路="畅速",
分辨率="2K",
宽高比="16:9",
生图数量=4,
质量="最高",
复杂度="中",
输出格式="webp",
背景="transparent",
缩放图片="智能缩放",
))
self.assertEqual(tuple(result[0].shape), (4, 4, 6, 3))
self.assertTrue(all(call["complexity"] == "medium" for call in calls))
self.assertEqual(len(calls), 4)
self.assertGreater(maximum_active, 1)
self.assertTrue(all(call["n"] == 1 for call in calls))
self.assertTrue(all(call["model"] == "gpt-image-2.5-sunburst-sp" for call in calls))
self.assertTrue(all(call["model"] == "gpt-image-2.6-sunburst-sp" for call in calls))
self.assertTrue(all(call["special_price_parallel"] is False for call in calls))
self.assertTrue(all(call["size"] == "3648x2048" for call in calls))
self.assertTrue(all(call["quality"] == "max" for call in calls))
@@ -515,6 +577,75 @@ class O1keyImageGeneratorTests(unittest.TestCase):
self.assertTrue(all("moderation" not in call for call in calls))
self.assertTrue(all(call["resize_mode"] == "智能缩放" for call in calls))
def test_gpt_26_gif_sends_frame_fields_and_rejects_edit(self):
calls = []
class FakeClient:
def __init__(self):
self.base_url = ""
self.response_log_enabled = True
self.poll_log_enabled = True
async def generate_image_async(self, **kwargs):
calls.append(kwargs)
return [Image.new("RGB", (6, 4), "red")]
@staticmethod
def _pil_list_to_tensor(images):
return torch.zeros((len(images), 4, 6, 3), dtype=torch.float32)
with (
patch(
"comfyui_o1key.nodes.o1key_image_generator.GptImageClient",
FakeClient,
),
patch(
"comfyui_o1key.nodes.o1key_image_generator.get_base_url_by_route",
return_value="https://example.invalid",
),
):
result = asyncio.run(O1keyImageGenerator.execute(
prompt="一只宇航猫",
模型="gpt-image-2.6-flare",
模型线路="畅速",
分辨率="智能",
宽高比="1:1",
生图数量=1,
质量="自动",
复杂度="低",
输出格式="gif",
帧数=12,
帧时长ms=205,
背景="auto",
缩放图片="不缩放",
))
self.assertEqual(tuple(result[0].shape), (1, 4, 6, 3))
self.assertEqual(calls[0]["output_format"], "gif")
self.assertEqual(calls[0]["frame_count"], 12)
self.assertEqual(calls[0]["frame_duration_ms"], 200)
self.assertEqual(calls[0]["complexity"], "low")
fake_ref = torch.zeros((1, 8, 8, 3), dtype=torch.float32)
with (
patch(
"comfyui_o1key.nodes.o1key_image_generator._load_reference_tensors",
return_value={0: fake_ref},
),
self.assertRaisesRegex(ValueError, "纯文生图"),
):
asyncio.run(O1keyImageGenerator.execute(
prompt="一只宇航猫",
模型="gpt-image-2.6-sunburst",
模型线路="畅速",
分辨率="智能",
宽高比="1:1",
生图数量=1,
质量="自动",
输出格式="svg",
参考图清单='[{"name":"a.png","subfolder":"","type":"input"}]',
))
def test_seedream_direct_execution_sends_exact_size_and_output_format(self):
calls = []
session = object()