按 OpenAI 官方放开 GIF+参考图,SVG 仍仅文生图;有蒙版禁用 GIF/SVG
This commit is contained in:
@@ -467,14 +467,41 @@ class GPTImage26SvgGifTests(unittest.TestCase):
|
||||
|
||||
def test_svg_gif_reject_edit_inputs(self):
|
||||
import torch
|
||||
from comfyui_o1key.utils.o1key_image_catalog import validate_gpt_image_vector_output
|
||||
|
||||
client = object.__new__(GptImageClient)
|
||||
fake = torch.zeros((1, 8, 8, 3))
|
||||
for output_format in ("svg", "gif"):
|
||||
with self.assertRaisesRegex(ValueError, "纯文生图"):
|
||||
client._build_async_generate_body(
|
||||
"test", "gpt-image-2.6-sunburst", "high", None, 1,
|
||||
image_list=[fake], output_format=output_format,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "纯文生图"):
|
||||
client._build_async_generate_body(
|
||||
"test", "gpt-image-2.6-sunburst", "high", None, 1,
|
||||
image_list=[fake], output_format="svg",
|
||||
)
|
||||
# GIF + reference images is allowed (OpenAI image edit guidance).
|
||||
validate_gpt_image_vector_output(
|
||||
"gpt-image-2.6-sunburst",
|
||||
"gif",
|
||||
has_images=True,
|
||||
has_mask=False,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "纯文生图"):
|
||||
validate_gpt_image_vector_output(
|
||||
"gpt-image-2.6-sunburst",
|
||||
"svg",
|
||||
has_images=False,
|
||||
has_mask=True,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "不支持蒙版"):
|
||||
validate_gpt_image_vector_output(
|
||||
"gpt-image-2.6-sunburst",
|
||||
"gif",
|
||||
has_images=True,
|
||||
has_mask=True,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "不支持蒙版"):
|
||||
client._build_async_generate_body(
|
||||
"test", "gpt-image-2.6-sunburst", "high", None, 1,
|
||||
image_list=[fake], mask_tensor=fake, output_format="gif",
|
||||
)
|
||||
|
||||
def test_materialize_gif_expands_frames_and_keeps_bytes(self):
|
||||
from io import BytesIO
|
||||
|
||||
@@ -163,3 +163,32 @@ for (const nodeType of ["O1keyGPTImage", "O1keyGPTImageBatch"]) {
|
||||
assert.equal(format.options.values.includes(nodeType === "O1keyGPTImageBatch" ? "GIF" : "gif"), false);
|
||||
assert.equal(frameCount.hidden, true);
|
||||
}
|
||||
|
||||
for (const nodeType of ["O1keyGPTImage", "O1keyGPTImageBatch"]) {
|
||||
const node = makeNode("gpt-image-2.6-sunburst", "最高", nodeType);
|
||||
const size = () => [150, 20];
|
||||
const complexity = { name: "复杂度", value: "中", options: {}, computeSize: size };
|
||||
const formatName = nodeType === "O1keyGPTImageBatch" ? "图片输出格式" : "输出格式";
|
||||
const gifValue = nodeType === "O1keyGPTImageBatch" ? "GIF" : "gif";
|
||||
const svgValue = nodeType === "O1keyGPTImageBatch" ? "SVG" : "svg";
|
||||
const format = {
|
||||
name: formatName,
|
||||
value: nodeType === "O1keyGPTImageBatch" ? "PNG" : "png",
|
||||
options: { values: [] },
|
||||
callback() {},
|
||||
};
|
||||
const frameCount = { name: "帧数", value: 9, options: {}, computeSize: size };
|
||||
const frameDuration = { name: "帧时长ms", value: 200, options: {}, computeSize: size };
|
||||
node.widgets.push(complexity, format, frameCount, frameDuration);
|
||||
extension.nodeCreated(node);
|
||||
|
||||
node.widgets.push({ name: "参考图1", value: "ref.png", options: {} });
|
||||
node.modelWidget.callback();
|
||||
assert.equal(format.options.values.includes(gifValue), true, "refs keep gif");
|
||||
assert.equal(format.options.values.includes(svgValue), false, "refs hide svg");
|
||||
|
||||
node.widgets.push({ name: "遮罩", value: "mask.png", options: {} });
|
||||
node.modelWidget.callback();
|
||||
assert.equal(format.options.values.includes(gifValue), false, "mask hides gif");
|
||||
assert.equal(format.options.values.includes(svgValue), false, "mask hides svg");
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ 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):
|
||||
def test_gpt_26_gif_sends_frame_fields_and_vector_edit_rules(self):
|
||||
calls = []
|
||||
|
||||
class FakeClient:
|
||||
@@ -627,6 +627,47 @@ class O1keyImageGeneratorTests(unittest.TestCase):
|
||||
self.assertEqual(calls[0]["complexity"], "low")
|
||||
|
||||
fake_ref = torch.zeros((1, 8, 8, 3), dtype=torch.float32)
|
||||
gif_ref_calls = []
|
||||
|
||||
class FakeGifRefClient(FakeClient):
|
||||
async def generate_image_async(self, **kwargs):
|
||||
gif_ref_calls.append(kwargs)
|
||||
return [Image.new("RGB", (6, 4), "blue")]
|
||||
|
||||
with (
|
||||
patch(
|
||||
"comfyui_o1key.nodes.o1key_image_generator.GptImageClient",
|
||||
FakeGifRefClient,
|
||||
),
|
||||
patch(
|
||||
"comfyui_o1key.nodes.o1key_image_generator.get_base_url_by_route",
|
||||
return_value="https://example.invalid",
|
||||
),
|
||||
patch(
|
||||
"comfyui_o1key.nodes.o1key_image_generator._load_reference_tensors",
|
||||
return_value={0: fake_ref},
|
||||
),
|
||||
):
|
||||
gif_ref_result = asyncio.run(O1keyImageGenerator.execute(
|
||||
prompt="一只宇航猫",
|
||||
模型="gpt-image-2.6-flare",
|
||||
模型线路="畅速",
|
||||
分辨率="智能",
|
||||
宽高比="1:1",
|
||||
生图数量=1,
|
||||
质量="自动",
|
||||
复杂度="低",
|
||||
输出格式="gif",
|
||||
帧数=12,
|
||||
帧时长ms=205,
|
||||
背景="auto",
|
||||
缩放图片="不缩放",
|
||||
参考图清单='[{"name":"a.png","subfolder":"","type":"input"}]',
|
||||
))
|
||||
self.assertEqual(tuple(gif_ref_result[0].shape), (1, 4, 6, 3))
|
||||
self.assertEqual(gif_ref_calls[0]["output_format"], "gif")
|
||||
self.assertIsNotNone(gif_ref_calls[0].get("image_tensor"))
|
||||
|
||||
with (
|
||||
patch(
|
||||
"comfyui_o1key.nodes.o1key_image_generator._load_reference_tensors",
|
||||
|
||||
@@ -4880,7 +4880,15 @@ const nanoThinkingSource = fs.readFileSync(new URL("../web/js/nanoBananaThinking
|
||||
assert.equal(node._o1igFrameDurationField.style.display, "");
|
||||
node._o1igReferences = [{ name: "a.png", subfolder: "", type: "input" }];
|
||||
syncGptOutputOptions(node);
|
||||
assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "gif"), true);
|
||||
assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "svg"), false);
|
||||
assert.equal(node._o1igOutputFormat.value, "gif");
|
||||
assert.equal(node._o1igFrameCountField.style.display, "");
|
||||
assert.equal(node._o1igFrameDurationField.style.display, "");
|
||||
node._o1igMask = { name: "mask.png", subfolder: "", type: "input" };
|
||||
syncGptOutputOptions(node);
|
||||
assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "gif"), false);
|
||||
assert.equal(node._o1igOutputFormat._o1igOptions.some((option) => option.value === "svg"), false);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -163,14 +163,44 @@ class PayloadTests(unittest.TestCase):
|
||||
"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": "svg",
|
||||
"references": [{"name": "a.png", "subfolder": "", "type": "input"}],
|
||||
})
|
||||
gif_with_refs = JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
"batch_id": str(__import__("uuid").uuid4()),
|
||||
"model": "gpt-image-2.6-flare",
|
||||
"output_format": "gif",
|
||||
"frame_count": 12,
|
||||
"frame_duration_ms": 205,
|
||||
"references": [{"name": "a.png", "subfolder": "", "type": "input"}],
|
||||
})
|
||||
self.assertEqual(gif_with_refs["output_format"], "gif")
|
||||
self.assertEqual(gif_with_refs["frame_count"], 12)
|
||||
self.assertEqual(len(gif_with_refs["references"]), 1)
|
||||
with self.assertRaisesRegex(ValueError, "纯文生图"):
|
||||
JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
"batch_id": str(__import__("uuid").uuid4()),
|
||||
"model": "gpt-image-2.6-flare",
|
||||
"output_format": "svg",
|
||||
"references": [{"name": "a.png", "subfolder": "", "type": "input"}],
|
||||
"mask": {"name": "mask.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",
|
||||
"references": [{"name": "a.png", "subfolder": "", "type": "input"}],
|
||||
"mask": {"name": "mask.png", "subfolder": "", "type": "input"},
|
||||
})
|
||||
with self.assertRaisesRegex(ValueError, "帧数"):
|
||||
JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
|
||||
Reference in New Issue
Block a user