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
+91 -18
View File
@@ -18,6 +18,20 @@ COMFY_ROOT = CUSTOM_NODES_ROOT.parent
sys.path.insert(0, str(COMFY_ROOT))
sys.path.insert(0, str(CUSTOM_NODES_ROOT))
import types as _types
# Avoid package-wide node registry (CUDA probe) in the portable CPU torch build.
_plugin = _types.ModuleType("comfyui_o1key")
_plugin.__path__ = [str(ROOT)]
sys.modules["comfyui_o1key"] = _plugin
for _child in ("nodes", "utils", "clients"):
_mod = _types.ModuleType(f"comfyui_o1key.{_child}")
_mod.__path__ = [str(ROOT / _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 comfyui_o1key.utils import o1key_image_jobs as JOBS # noqa: E402
@@ -70,12 +84,12 @@ class PayloadTests(unittest.TestCase):
self.assertEqual(job["generator_node_id"], 1)
self.assertEqual(job["save_node_id"], 2)
def test_missing_thinking_level_defaults_to_low(self):
def test_missing_thinking_level_and_resize_defaults(self):
payload = _payload()
payload.pop("thinking_level")
job = JOBS.normalize_job_payload(payload)
self.assertEqual(job["thinking_level"], "低")
self.assertEqual(job["resize_mode"], "不缩放")
self.assertEqual(job["thinking_level"], "高")
self.assertEqual(job["resize_mode"], "智能缩放")
self.assertNotIn("color_correction", job)
self.assertEqual(job["filename_prefix"], "o1key")
self.assertEqual(job["save_format"], "原始")
@@ -110,6 +124,62 @@ class PayloadTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "Nano Banana 2"):
JOBS.normalize_job_payload(payload)
def test_26_complexity_normalizes_default_and_rejects_invalid_values(self):
for variant in ("sunburst", "flare"):
model = f"gpt-image-2.6-{variant}"
job = JOBS.normalize_job_payload({**_payload(), "model": model})
self.assertEqual(job["complexity"], "high")
for value, expected in (("low", "low"), ("medium", "medium"), ("high", "high"),
("低", "low"), ("中", "medium"), ("高", "high")):
job = JOBS.normalize_job_payload({**_payload(), "model": model, "complexity": value})
self.assertEqual(job["complexity"], expected)
for value in ("invalid", "", [], 1):
with self.subTest(model=model, value=value), self.assertRaisesRegex(ValueError, "复杂度"):
JOBS.normalize_job_payload({**_payload(), "model": model, "complexity": value})
job = JOBS.normalize_job_payload({**_payload(), "model": "gpt-image-2.5-sunburst", "complexity": "low"})
self.assertNotIn("complexity", job)
def test_26_svg_gif_normalize_and_reject_edit(self):
for output_format in ("svg", "gif"):
job = JOBS.normalize_job_payload({
**_payload(),
"batch_id": str(__import__("uuid").uuid4()),
"model": "gpt-image-2.6-sunburst",
"output_format": output_format,
"frame_count": 12 if output_format == "gif" else 9,
"frame_duration_ms": 205 if output_format == "gif" else 200,
})
self.assertEqual(job["output_format"], output_format)
if output_format == "gif":
self.assertEqual(job["frame_count"], 12)
self.assertEqual(job["frame_duration_ms"], 200)
else:
self.assertNotIn("frame_count", job)
self.assertNotIn("frame_duration_ms", job)
with self.assertRaisesRegex(ValueError, "仅支持 GPT Image 2.6"):
JOBS.normalize_job_payload({
**_payload(),
"batch_id": str(__import__("uuid").uuid4()),
"model": "gpt-image-2.5-sunburst",
"output_format": output_format,
})
with self.assertRaisesRegex(ValueError, "纯文生图"):
JOBS.normalize_job_payload({
**_payload(),
"batch_id": str(__import__("uuid").uuid4()),
"model": "gpt-image-2.6-flare",
"output_format": output_format,
"references": [{"name": "a.png", "subfolder": "", "type": "input"}],
})
with self.assertRaisesRegex(ValueError, "帧数"):
JOBS.normalize_job_payload({
**_payload(),
"batch_id": str(__import__("uuid").uuid4()),
"model": "gpt-image-2.6-flare",
"output_format": "gif",
"frame_count": 1,
})
def test_unified_limits_and_gpt_parameters(self):
payload = _payload()
payload.update({
@@ -146,7 +216,8 @@ class PayloadTests(unittest.TestCase):
self.assertEqual(default_gpt["resize_mode"], "智能缩放")
self.assertEqual(default_gpt["save_format"], "原始")
for model in ("gpt-image-2.5-sunburst", "gpt-image-2.5-flare"):
for model in ("gpt-image-2.5-sunburst", "gpt-image-2.5-flare",
"gpt-image-2.6-sunburst", "gpt-image-2.6-flare"):
with self.subTest(model=model):
gpt_25 = JOBS.normalize_job_payload({
**_payload(),
@@ -353,7 +424,7 @@ class PayloadTests(unittest.TestCase):
grouped = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "一组搭配+多模特",
"batch_mode": "整组素材→多个目标",
"references": outfits[:9],
"model_references": models,
})
@@ -364,7 +435,7 @@ class PayloadTests(unittest.TestCase):
cartesian = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "全部搭配×全部模特",
"batch_mode": "每张素材×每张目标",
"references": outfits,
"model_references": models,
})
@@ -376,7 +447,7 @@ class PayloadTests(unittest.TestCase):
single_references = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "单图素材批量",
"batch_mode": "每张素材单独出图",
"references": outfits[:3],
"model_references": models[:1],
})
@@ -404,7 +475,7 @@ class PayloadTests(unittest.TestCase):
single_fifty = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "单图素材批量",
"batch_mode": "每张素材单独出图",
"references": fifty_references,
})
self.assertEqual(single_fifty["total_task_count"], 50)
@@ -412,7 +483,7 @@ class PayloadTests(unittest.TestCase):
grouped_fifty_targets = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "一组搭配+多模特",
"batch_mode": "整组素材→多个目标",
"references": outfits[:1],
"model_references": fifty_models,
})
@@ -422,7 +493,7 @@ class PayloadTests(unittest.TestCase):
JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "单图素材批量",
"batch_mode": "每张素材单独出图",
"references": [
*fifty_references,
{"name": "overflow.png", "subfolder": "", "type": "input"},
@@ -433,7 +504,7 @@ class PayloadTests(unittest.TestCase):
JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "一组搭配+多模特",
"batch_mode": "整组素材→多个目标",
"references": outfits,
"model_references": models[:1],
})
@@ -641,7 +712,7 @@ class GptExecutionTests(unittest.IsolatedAsyncioTestCase):
"model": "gpt-image-2",
"resolution": "1K",
"batch_enabled": True,
"batch_mode": "单图素材批量",
"batch_mode": "每张素材单独出图",
"references": references,
})
job["reference_paths"] = tuple(item["name"] for item in references)
@@ -700,7 +771,7 @@ class GptExecutionTests(unittest.IsolatedAsyncioTestCase):
"model": "gpt-image-2",
"resolution": "1K",
"batch_enabled": True,
"batch_mode": "全部搭配×全部模特",
"batch_mode": "每张素材×每张目标",
"references": [
{"name": os.path.basename(path), "subfolder": "", "type": "input"}
for path in outfit_paths
@@ -769,7 +840,8 @@ class GptExecutionTests(unittest.IsolatedAsyncioTestCase):
job = JOBS.normalize_job_payload({
**_payload(),
"model": "gpt-image-2.5-sunburst",
"model": "gpt-image-2.6-sunburst",
"complexity": "low",
"resolution": "4K",
"aspect_ratio": "智能",
"prompt": "紫色方块\n---\n绿色圆形",
@@ -802,7 +874,8 @@ class GptExecutionTests(unittest.IsolatedAsyncioTestCase):
self.assertGreater(maximum_active, 1)
self.assertTrue(all(call["n"] == 1 for call in calls))
self.assertTrue(all(call["quality"] == "xhigh" 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["complexity"] == "low" for call in calls))
self.assertTrue(all(call["special_price_parallel"] is False for call in calls))
self.assertTrue(all(call["size"] == "2880x2880" for call in calls))
self.assertTrue(all(call["output_format"] == "webp" for call in calls))
@@ -902,7 +975,7 @@ class NanoExecutionTests(unittest.IsolatedAsyncioTestCase):
job = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "单图素材批量",
"batch_mode": "每张素材单独出图",
"references": references,
})
job["reference_paths"] = tuple(item["name"] for item in references)
@@ -969,7 +1042,7 @@ class NanoExecutionTests(unittest.IsolatedAsyncioTestCase):
job = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "全部搭配×全部模特",
"batch_mode": "每张素材×每张目标",
"references": [
{"name": os.path.basename(path), "subfolder": "", "type": "input"}
for path in outfit_paths
@@ -1162,7 +1235,7 @@ class IsolationTests(unittest.TestCase):
job = JOBS.normalize_job_payload({
**_payload(),
"batch_enabled": True,
"batch_mode": "全部搭配×全部模特",
"batch_mode": "每张素材×每张目标",
"references": [{"name": "outfit.png", "subfolder": "", "type": "input"}],
"model_references": [{"name": "model.png", "subfolder": "", "type": "input"}],
})