Add Nano Banana 2.1 and preserve image workflow values
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
@@ -54,6 +55,7 @@ class NanoBananaDynamicInputTests(unittest.TestCase):
|
||||
self.assertNotIn("网络", inputs)
|
||||
self.assertFalse(inputs["模型线路"].advanced)
|
||||
self.assertEqual(inputs["模型"].options, NANO_BANANA_MODEL_OPTIONS)
|
||||
self.assertEqual(inputs["模型"].default, "Nano Banana 2.1")
|
||||
self.assertEqual(inputs["模型线路"].options, NANO_BANANA_ROUTE_OPTIONS)
|
||||
self.assertEqual(inputs["分辨率"].options, ["1K", "2K", "4K"])
|
||||
self.assertEqual(
|
||||
@@ -96,6 +98,9 @@ class NanoBananaDynamicInputTests(unittest.TestCase):
|
||||
|
||||
def test_model_route_matrix_matches_api_model_names(self):
|
||||
expected = {
|
||||
("Nano Banana 2.1", "畅速"): "gemini-nano-banana-2.1-sp",
|
||||
("Nano Banana 2.1", "直连"): "gemini-nano-banana-2.1-sd",
|
||||
("Nano Banana 2.1", "专线"): "gemini-nano-banana-2.1",
|
||||
("Nano Banana Pro", "畅速"): "gemini-3-pro-image-c-sp",
|
||||
("Nano Banana 2", "畅速"): "gemini-3.1-flash-image-c-sp",
|
||||
("Nano Banana 2 Lite", "畅速"): "gemini-3.1-flash-lite-image-c-sp",
|
||||
@@ -113,6 +118,40 @@ class NanoBananaDynamicInputTests(unittest.TestCase):
|
||||
for key, model_id in expected.items():
|
||||
self.assertEqual(resolve_nano_banana_model(*key), model_id)
|
||||
|
||||
def test_nano_banana_21_supports_extended_ratios_and_existing_resolutions(self):
|
||||
for node in (NanoBanana, BatchNanoBananaPro):
|
||||
for resolution in ("1K", "2K", "4K"):
|
||||
for ratio in ("1:4", "1:8", "4:1", "8:1"):
|
||||
with self.subTest(node=node.__name__, resolution=resolution, ratio=ratio):
|
||||
node._validate_model_config("Nano Banana 2.1", ratio, resolution)
|
||||
|
||||
def test_nano_banana_21_forwards_route_thinking_and_search(self):
|
||||
image = Image.new("RGB", (4, 4), "purple")
|
||||
for route, model_id in (
|
||||
("畅速", "gemini-nano-banana-2.1-sp"),
|
||||
("直连", "gemini-nano-banana-2.1-sd"),
|
||||
("专线", "gemini-nano-banana-2.1"),
|
||||
):
|
||||
with self.subTest(route=route), patch(
|
||||
"comfyui_o1key.nodes.nano_banana._process_batch_async",
|
||||
new=AsyncMock(return_value=[{"success": True, "output_images": [image]}]),
|
||||
) as generate, patch(
|
||||
"comfyui_o1key.nodes.nano_banana.get_api_key_or_raise", return_value="test",
|
||||
), patch(
|
||||
"comfyui_o1key.nodes.nano_banana.get_base_url_by_route",
|
||||
return_value="https://example.invalid",
|
||||
), patch(
|
||||
"comfyui_o1key.nodes.nano_banana._get_client", side_effect=RuntimeError("offline"),
|
||||
):
|
||||
NanoBanana.execute(
|
||||
prompt="test", 模型="Nano Banana 2.1", 模型线路=route,
|
||||
分辨率="2K", 宽高比="1:8", 生图数量="2", 思考等级="低",
|
||||
_o1key_google_search=True,
|
||||
)
|
||||
self.assertEqual(generate.call_args.kwargs["model"], model_id)
|
||||
self.assertEqual(generate.call_args.kwargs["thinking_level"], "minimal")
|
||||
self.assertIs(generate.call_args.kwargs["google_search"], True)
|
||||
|
||||
def test_legacy_billing_values_resolve_to_equivalent_routes(self):
|
||||
self.assertEqual(
|
||||
resolve_nano_banana_model("Nano Banana Pro", "特价"),
|
||||
@@ -136,6 +175,8 @@ class BatchNanoBananaDynamicInputTests(unittest.TestCase):
|
||||
inputs = {item.id: item for item in schema.inputs}
|
||||
|
||||
self.assertEqual(schema.display_name, "Nano Banana 批量跑图")
|
||||
self.assertEqual(inputs["模型"].options, NANO_BANANA_MODEL_OPTIONS)
|
||||
self.assertEqual(inputs["模型"].default, "Nano Banana 2.1")
|
||||
self.assertEqual(
|
||||
[item.id for item in schema.inputs[:7]],
|
||||
["prompt", "模型", "模型线路", "思考等级", "分辨率", "宽高比", "图片路径数量"],
|
||||
@@ -199,6 +240,35 @@ class BatchNanoBananaDynamicInputTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "分辨率 '512' 无效"):
|
||||
BatchNanoBananaPro._validate_model_config("Nano Banana 2", "1:1", "512")
|
||||
|
||||
def test_nano_banana_21_batch_forwards_model_and_thinking_level(self):
|
||||
image = ImageInfo(Image.new("RGB", (4, 4), "purple"), "reference", ".png", "")
|
||||
for route, model_id in (
|
||||
("畅速", "gemini-nano-banana-2.1-sp"),
|
||||
("直连", "gemini-nano-banana-2.1-sd"),
|
||||
("专线", "gemini-nano-banana-2.1"),
|
||||
):
|
||||
with self.subTest(route=route), tempfile.TemporaryDirectory() as output_dir, patch.object(
|
||||
BatchNanoBananaPro, "_process_batch_async",
|
||||
new=AsyncMock(return_value=[{"success": True, "generated_count": 1}]),
|
||||
) as generate, patch(
|
||||
"comfyui_o1key.nodes.batch_nano_banana.load_images_from_folder", return_value=[image],
|
||||
), patch(
|
||||
"comfyui_o1key.nodes.batch_nano_banana.get_api_key_or_raise", return_value="test",
|
||||
), patch(
|
||||
"comfyui_o1key.nodes.batch_nano_banana.get_base_url_by_route",
|
||||
return_value="https://example.invalid",
|
||||
), patch(
|
||||
"comfyui_o1key.nodes.batch_nano_banana.GeminiAPIClient",
|
||||
side_effect=RuntimeError("offline"),
|
||||
):
|
||||
BatchNanoBananaPro.execute(
|
||||
prompt="test", 模型="Nano Banana 2.1", 模型线路=route,
|
||||
思考等级="高", 分辨率="4K", 宽高比="8:1",
|
||||
图片路径1="mock-input", 图片保存路径=output_dir,
|
||||
)
|
||||
self.assertEqual(generate.call_args.kwargs["model"], model_id)
|
||||
self.assertEqual(generate.call_args.kwargs["thinking_level"], "high")
|
||||
|
||||
def test_execute_unpacks_dynamic_folders_and_autogrow_references(self):
|
||||
first_reference = object()
|
||||
third_reference = object()
|
||||
|
||||
@@ -52,6 +52,7 @@ class O1keyImageGeneratorTests(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
list(UNIFIED_IMAGE_MODEL_OPTIONS),
|
||||
[
|
||||
"Nano Banana 2.1",
|
||||
"Nano Banana 2",
|
||||
"Nano Banana Pro",
|
||||
"gpt-image-2",
|
||||
@@ -97,6 +98,7 @@ class O1keyImageGeneratorTests(unittest.TestCase):
|
||||
self.assertEqual(count_input.options, [str(value) for value in range(1, 10)])
|
||||
self.assertEqual(count_input.default, "1")
|
||||
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.5-sunburst", model_input.options)
|
||||
self.assertIn("gpt-image-2.5-flare", model_input.options)
|
||||
@@ -366,6 +368,22 @@ class O1keyImageGeneratorTests(unittest.TestCase):
|
||||
|
||||
self.assertIs(execute.call_args.kwargs["_o1key_google_search"], False)
|
||||
|
||||
def test_default_model_delegates_nano_banana_21_with_search_and_thinking(self):
|
||||
image = torch.zeros((1, 8, 8, 3), dtype=torch.float32)
|
||||
with patch(
|
||||
"comfyui_o1key.nodes.o1key_image_generator.NanoBanana.execute",
|
||||
return_value=io.NodeOutput(image),
|
||||
) as execute:
|
||||
result = asyncio.run(O1keyImageGenerator.execute(
|
||||
prompt="test", 模型线路="直连", 思考等级="高",
|
||||
分辨率="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)
|
||||
|
||||
def test_error_wrappers_apply_to_every_model_family(self):
|
||||
raw = (
|
||||
"status_code=451, The provided prompt is considered unsafe and it "
|
||||
|
||||
@@ -88,6 +88,7 @@ class Element {
|
||||
append(...items) { this.children.push(...items); }
|
||||
prepend(...items) { this.children.unshift(...items); }
|
||||
replaceChildren(...items) { this.children = [...items]; }
|
||||
contains(element) { return this === element || this.children.some(child => child.contains?.(element)); }
|
||||
addEventListener(type, listener) { this.listeners.set(type, listener); }
|
||||
setAttribute(name, value) { this[name] = value; }
|
||||
dispatch(type, event = { stopPropagation() {} }) { return this.listeners.get(type)?.(event); }
|
||||
@@ -231,6 +232,9 @@ vm.runInContext(source, context, { filename: sourcePath.pathname });
|
||||
}
|
||||
|
||||
const setStatus = vm.runInContext("setStatus", context);
|
||||
const buildPanel = vm.runInContext("buildPanel", context);
|
||||
const restorePanelFromWidgets = vm.runInContext("restorePanelFromWidgets", context);
|
||||
const serializeGeneratorWidgets = vm.runInContext("serializeGeneratorWidgets", context);
|
||||
const makeDropdown = vm.runInContext("makeDropdown", context);
|
||||
const isGeneratedSeedControl = vm.runInContext("isGeneratedSeedControl", context);
|
||||
const hideBackendWidgets = vm.runInContext("hideBackendWidgets", context);
|
||||
@@ -372,6 +376,72 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
|
||||
assert.equal(unrelatedControl.hidden, undefined);
|
||||
}
|
||||
|
||||
{
|
||||
const names = [
|
||||
"prompt", "模型", "模型线路", "思考等级", "分辨率", "宽高比", "生图数量", "seed",
|
||||
"参考图清单", "质量", "输出格式", "蒙版清单", "缩放图片", "背景", "批量出图",
|
||||
"批量模式", "模特图清单", "命名规则", "filename_prefix", "格式", "保存位置", "在线搜索", "图层拆分",
|
||||
];
|
||||
const values = [
|
||||
"saved panel prompt", "Nano Banana 2.1", "专线", "高", "2K", "1:8", "4", 123,
|
||||
"[]", "自动", "jpeg", "{}", "不缩放", "auto", false,
|
||||
"一组搭配+多模特", "[]", "自定义前缀", "kept-prefix", "原始", "kept-location", "打开", false,
|
||||
];
|
||||
const widgets = names.map((name, index) => ({ name, value: values[index], options: {} }));
|
||||
const node = {
|
||||
comfyClass: "O1keyImageGenerator", widgets, size: [560, 1035], outputs: [],
|
||||
addDOMWidget(name, type, element, options) {
|
||||
const widget = { name, type, element, options };this.widgets.push(widget);return widget;
|
||||
},
|
||||
computeSize() { return [500, 1025]; },
|
||||
setSize(size) { this.size = size; },
|
||||
setDirtyCanvas() {},
|
||||
};
|
||||
buildPanel(node);
|
||||
const panel = node._o1igPanel;
|
||||
const count = node.widgets.length;
|
||||
buildPanel(node);
|
||||
assert.equal(node._o1igPanel, panel);
|
||||
assert.equal(node.widgets.length, count);
|
||||
assert.equal(panel.className, "o1ig-panel");
|
||||
assert.equal(node.widgets.length, names.length + 1, "Keep one panel rather than appending native action rows");
|
||||
assert.deepEqual(node.widgets.slice(0, names.length).map(widget => widget.name), names);
|
||||
assert.equal(node._o1igPrompt.tagName, "TEXTAREA");
|
||||
assert.equal(node._o1igGenerate.tagName, "BUTTON");
|
||||
assert.equal(node._o1igGenerate.className, "o1ig-generate");
|
||||
assert.equal(panel.children.at(-1), node._o1igGenerate, "Start generation stays at the bottom of the panel");
|
||||
const promptWrap = panel.children.find(child => child.className === "o1ig-prompt-wrap");
|
||||
assert.ok(promptWrap.children.includes(node._o1igPromptOptimize), "AI writing remains inside the prompt area");
|
||||
const seedField = node._o1igToolbar.children.find(child => child.children[1]?.className === "o1ig-seed");
|
||||
assert.equal(seedField.children[1].children[0], node._o1igSeed);
|
||||
assert.equal(seedField.children[1].children[1].title, "随机种子");
|
||||
assert.ok(node._o1igReferenceHeader.contains(node._o1igAdd));
|
||||
assert.ok(node._o1igReferenceHeader.contains(node._o1igCanvasPick));
|
||||
assert.equal(node._o1igRefs.children[0].className, "o1ig-empty-reference");
|
||||
node._o1igBatchToggle.dispatch("click");
|
||||
assert.equal(node._o1igBatchEnabled, true);
|
||||
assert.equal(node._o1igModelAssets.classList.contains("visible"), true);
|
||||
node._o1igBatchToggle.dispatch("click");
|
||||
assert.equal(node._o1igBatchEnabled, false);
|
||||
const computeSize = widgets[0].computeSize;
|
||||
widgets[0].options = {};widgets[0].hidden = false;
|
||||
restorePanelFromWidgets(node);
|
||||
assert.equal(widgets[0].options.hidden, true, "Keep backend fields hidden after a renderer switch");
|
||||
assert.equal(widgets[0].computeSize, computeSize);
|
||||
assert.equal(node._o1igModel.value, "Nano Banana 2.1");
|
||||
assert.equal(node._o1igSeed.value, "123");
|
||||
assert.equal(node._o1igFilenamePrefix.value, "kept-prefix");
|
||||
assert.equal(node._o1igSaveLocation.value, "kept-location");
|
||||
const saved = {};serializeGeneratorWidgets(node, saved);
|
||||
assert.equal(saved.widgets_values.length, names.length);
|
||||
assert.equal(saved.widgets_values[7], 123);
|
||||
assert.equal(saved.widgets_values[18], "kept-prefix");
|
||||
assert.equal(saved.widgets_values[20], "kept-location");
|
||||
const panelCss = source.slice(source.indexOf("const CSS"), source.indexOf(".o1igs-progress-host"));
|
||||
assert.doesNotMatch(panelCss, /#[0-9a-f]{3,8}\b|rgba?\(/i, "Use ComfyUI theme colours for every panel control and button");
|
||||
assert.doesNotMatch(source, /function nativeAction|function bindNativeWidget|_o1igNativeWidgetsReady/);
|
||||
}
|
||||
|
||||
{
|
||||
const linkId = 8800;
|
||||
const generator = {
|
||||
@@ -961,6 +1031,7 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
|
||||
styled: button.classList.contains("has-description"),
|
||||
}));
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(descriptions)), [
|
||||
{ model: "Nano Banana 2.1", description: "快速,批量", styled: true },
|
||||
{ model: "Nano Banana 2", description: "快速,批量", styled: true },
|
||||
{ model: "Nano Banana Pro", description: "高质量资产", styled: true },
|
||||
{ model: "GPT Image 2", description: "高质量,编辑", styled: true },
|
||||
@@ -1119,6 +1190,18 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
|
||||
assert.equal(node._o1igSaveFormatField.style.display, "");
|
||||
assert.equal(node._o1igResizeWarning.classList.contains("visible"), true);
|
||||
|
||||
node._o1igModel.value = "Nano Banana 2.1";
|
||||
syncModelOptions(node);
|
||||
assert.deepEqual(
|
||||
JSON.parse(JSON.stringify(node._o1igResolution._o1igOptions.map(option => option.value))),
|
||||
["智能", "1K", "2K", "4K"],
|
||||
);
|
||||
assert.equal(node._o1igRatio._o1igOptions.some(option => option.value === "1:8"), true);
|
||||
assert.equal(node._o1igThinkingField.style.display, "");
|
||||
assert.equal(node._o1igOnlineSearchField.style.display, "");
|
||||
assert.equal(node._o1igSaveFormatField.style.display, "");
|
||||
assert.equal(widgets.find((widget) => widget.name === "模型").value, "Nano Banana 2.1");
|
||||
|
||||
node._o1igModel.value = "Nano Banana 2 Lite";
|
||||
syncModelOptions(node);
|
||||
assert.equal(node._o1igResolution._o1igOptions.some((option) => option.value === "512"), true);
|
||||
@@ -2702,7 +2785,7 @@ assert.doesNotMatch(savePanelSource, /addDOMWidget/);
|
||||
assert.doesNotMatch(savePanelSource, /prefixWidget\.hidden = true/);
|
||||
assert.doesNotMatch(source, /installNativeMinimumSize\(nodeType, SAVE_NODE_LAYOUT_SIZE\)/);
|
||||
assert.match(source, /lucide--download.*lucide--refresh-cw/);
|
||||
assert.match(source, /font-size:12px;font-weight:500;line-height:1\.4;letter-spacing:\.035em/);
|
||||
assert.match(source, /--o1ig-surface:var\(--component-node-widget-background,var\(--comfy-input-bg\)\)/);
|
||||
assert.match(source, /o1ig-select-caret svg\{display:block;width:12px;height:12px/);
|
||||
assert.match(source, /const GENERATOR_DEFAULT_SIZE = \[560, 1035\]/);
|
||||
assert.doesNotMatch(source, /o1key-save-custom-prefix/);
|
||||
@@ -2717,7 +2800,7 @@ assert.match(source, /delete nodeData\.input\.optional\.external_prompt/);
|
||||
assert.doesNotMatch(source, /app\.queuePrompt\(0, 1, \[saveNode\.id\]\)/);
|
||||
assert.match(source, /\.o1ig-refs\{[\s\S]*?flex:0 0 109px[\s\S]*?min-height:109px/);
|
||||
assert.match(source, /\.o1ig-thumb\{[\s\S]*?flex:0 0 102px;height:102px/);
|
||||
assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:#111/);
|
||||
assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:var\(--o1ig-surface\)/);
|
||||
assert.match(source, /referenceActions\.append\(add, canvasPick\)/);
|
||||
assert.match(source, /modelActions\.append\(modelAdd, modelCanvasPick\)/);
|
||||
assert.match(source, /window\.o1keyCanvasImagePicker = Object\.freeze/);
|
||||
@@ -2732,16 +2815,16 @@ assert.match(source, /\.o1ig-thumb\.o1ig-dragging::before\{[\s\S]*?content:"移
|
||||
assert.match(source, /\.o1ig-refs\.o1ig-reordering\{/);
|
||||
assert.match(source, /\.o1ig-thumb\.o1ig-drop-before\{transform:translateX\(7px\)/);
|
||||
assert.match(source, /\.o1ig-empty-reference:hover,\.o1ig-empty-reference\.drag\{/);
|
||||
assert.match(source, /\.o1ig-toolbar\{[^\n]*grid-template-columns:repeat\(2,minmax\(0,1fr\)\)/);
|
||||
assert.match(source, /\.o1ig-field\{display:flex;flex-direction:column/);
|
||||
assert.match(source, /\.o1ig-toolbar\{[^\n]*grid-template-columns:minmax\(0,1fr\)/);
|
||||
assert.match(source, /\.o1ig-field\{display:grid;grid-template-columns:104px minmax\(0,1fr\)/);
|
||||
assert.match(source, /makePanelSectionTitle\("画面描述"\)/);
|
||||
assert.match(source, /makePanelSectionTitle\("生成参数"\)/);
|
||||
assert.match(source, /makePanelSectionTitle\("保存设置"\)/);
|
||||
assert.match(source, /filenamePrefixField\.classList\.add\("o1ig-field-wide"\)/);
|
||||
assert.match(source, /saveLocationField\.classList\.add\("o1ig-field-wide"\)/);
|
||||
assert.match(source, /o1ig-resize-warning\{display:none;color:#d5aa62/);
|
||||
assert.match(source, /o1ig-resize-warning\{display:none;grid-column:2;color:var\(--o1ig-muted\)/);
|
||||
assert.match(source, /o1ig-resize-warning\.visible\{display:block/);
|
||||
assert.match(source, /o1ig-seed\{[\s\S]*grid-template-columns:minmax\(0,1fr\) 34px;gap:0/);
|
||||
assert.match(source, /o1ig-seed\{[\s\S]*grid-template-columns:minmax\(0,1fr\) 28px;gap:0/);
|
||||
assert.match(source, /o1ig-seed button\{[\s\S]*border-left:1px solid/);
|
||||
assert.match(source, /className = "o1ig-prompt-optimize"/);
|
||||
assert.match(source, /className = "o1ig-prompt-optimize-status"/);
|
||||
@@ -2895,7 +2978,7 @@ assert.match(source, /jobPayload\.google_search = true/);
|
||||
assert.match(source, /jobPayload\.layer_decomposition = true/);
|
||||
assert.match(source, /if \(layerDecomposition\) \{\s*layerSaveNode = acquireLayerSaveNodeForBatch\(node, saveNode\);/);
|
||||
assert.match(source, /layerDecomposition,\s*retrySlotIndex,/);
|
||||
assert.match(source, /node\._o1igModel\.value === "Nano Banana 2"/);
|
||||
assert.match(source, /\["Nano Banana 2\.1", "Nano Banana 2"\]\.includes\(node\._o1igModel\.value\)/);
|
||||
assert.match(source, /node\._o1igOnlineSearch\.value === "打开"/);
|
||||
assert.match(source, /batch_enabled: retryTask \? false : Boolean\(node\._o1igBatchEnabled\)/);
|
||||
assert.match(source, /model_references: retryTask \|\| node\._o1igBatchMode\.value === BATCH_MODE_SINGLE_REFERENCES/);
|
||||
@@ -2969,6 +3052,27 @@ assert.match(migrationSource, /原生 seed 参数/);
|
||||
migrationContext,
|
||||
);
|
||||
const legacyRedCastValues = [1.0, 8.0, 0.1, "", 62.0, 15.0];
|
||||
const nativeValues = [
|
||||
"legacy native prompt", "Nano Banana 2.1", "专线", "高", "2K", "1:8", "4", 678803244,
|
||||
"[]", "最高", "png", "{}", "智能缩放", "transparent", false,
|
||||
"一组搭配+多模特", "[]", "自定义前缀", "legacy-prefix", "原始", "relative-save", "打开", false,
|
||||
];
|
||||
const oldPanelValues = [...nativeValues];
|
||||
oldPanelValues.splice(8, 0, "randomize");
|
||||
oldPanelValues.push("");
|
||||
const nativeGraph = {
|
||||
nodes: [{ type: "O1keyImageGenerator", widgets_values: oldPanelValues }],
|
||||
definitions: { subgraphs: [{
|
||||
nodes: [{ type: "O1keyImageGenerator", widgets_values: [...oldPanelValues] }],
|
||||
}] },
|
||||
};
|
||||
migrationExtension.beforeConfigureGraph(nativeGraph);
|
||||
assert.deepEqual(nativeGraph.nodes[0].widgets_values, nativeValues);
|
||||
assert.deepEqual(nativeGraph.definitions.subgraphs[0].nodes[0].widgets_values, nativeValues);
|
||||
migrationExtension.beforeConfigureGraph(nativeGraph);
|
||||
assert.deepEqual(nativeGraph.nodes[0].widgets_values, nativeValues);
|
||||
assert.deepEqual(nativeGraph.definitions.subgraphs[0].nodes[0].widgets_values, nativeValues);
|
||||
|
||||
const legacyRedCastGraph = {
|
||||
nodes: [{ type: "O1keyAutoRedCast", widgets_values: legacyRedCastValues }],
|
||||
};
|
||||
@@ -3182,6 +3286,22 @@ assert.match(migrationSource, /原生 seed 参数/);
|
||||
"不缩放", "原始", 95, "和原始图片名保持一致", "", 0,
|
||||
]);
|
||||
|
||||
for (const [type, original] of [
|
||||
["NanoBanana", legacyNanoValues],
|
||||
["BatchNanoBananaPro", legacyBatchNanoValues],
|
||||
["O1keyImageGenerator", movedGeneratorValues],
|
||||
]) {
|
||||
for (const model of ["Nano Banana 2.1", "Nano Banana 2"]) {
|
||||
const values = [...original];
|
||||
values[1] = model;
|
||||
const expected = [...values];
|
||||
const graph = { nodes: [{ type, widgets_values: values }] };
|
||||
migrationExtension.beforeConfigureGraph(graph);
|
||||
migrationExtension.beforeConfigureGraph(graph);
|
||||
assert.deepEqual(values, expected);
|
||||
}
|
||||
}
|
||||
|
||||
const stringQualityValues = [
|
||||
"prompt", "Nano Banana 2", "畅速", "高", "2K", "1:1",
|
||||
"1个路径", "D:\\images", "关闭", 0, "JPEG", "95",
|
||||
@@ -4033,3 +4153,32 @@ assert.match(migrationSource, /原生 seed 参数/);
|
||||
}
|
||||
|
||||
console.log("o1key image generator frontend tests passed");
|
||||
|
||||
const nanoThinkingSource = fs.readFileSync(new URL("../web/js/nanoBananaThinkingLevel.js", import.meta.url), "utf8");
|
||||
|
||||
{
|
||||
let thinkingExtension;
|
||||
vm.runInNewContext(nanoThinkingSource.replace(/^import .*;\s*$/gm, ""), {
|
||||
app: { registerExtension(extension) { thinkingExtension = extension; } },
|
||||
requestAnimationFrame(callback) { callback(); },
|
||||
});
|
||||
for (const comfyClass of ["NanoBanana", "BatchNanoBananaPro"]) {
|
||||
const model = { name: "模型", value: "Nano Banana 2.1", callback() { return "model-changed"; } };
|
||||
const computeSize = () => [100, 20];
|
||||
const thinking = { name: "思考等级", value: "高", computeSize };
|
||||
const node = { comfyClass, widgets: [model, thinking], setDirtyCanvas() {} };
|
||||
thinkingExtension.nodeCreated(node);
|
||||
assert.equal(thinking.hidden, false);
|
||||
assert.equal(thinking.options.hidden, false);
|
||||
for (const value of ["Nano Banana Pro", "Nano Banana 2 Lite", "Nano Banana 2", "Nano Banana 2.1"]) {
|
||||
model.value = value;
|
||||
assert.equal(model.callback(), "model-changed");
|
||||
assert.equal(thinking.hidden, !["Nano Banana 2", "Nano Banana 2.1"].includes(value));
|
||||
assert.equal(thinking.value, "高");
|
||||
}
|
||||
assert.equal(thinking.computeSize, computeSize);
|
||||
const callback = model.callback;
|
||||
thinkingExtension.loadedGraphNode(node);
|
||||
assert.equal(model.callback, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class PayloadTests(unittest.TestCase):
|
||||
"智能",
|
||||
)
|
||||
|
||||
for model in ("Nano Banana 2", "gpt-image-2", "Seedream 5.0 Pro"):
|
||||
for model in ("Nano Banana 2.1", "Nano Banana 2", "gpt-image-2", "Seedream 5.0 Pro"):
|
||||
with self.subTest(model=model):
|
||||
job = JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
@@ -293,12 +293,13 @@ class PayloadTests(unittest.TestCase):
|
||||
"references": [{"name": "poster.png", "subfolder": "", "type": "input"}],
|
||||
})
|
||||
|
||||
def test_google_search_is_kept_only_for_nano_banana_2_when_true(self):
|
||||
enabled = JOBS.normalize_job_payload({**_payload(), "google_search": True})
|
||||
self.assertIs(enabled["google_search"], True)
|
||||
|
||||
disabled = JOBS.normalize_job_payload({**_payload(), "google_search": False})
|
||||
self.assertNotIn("google_search", disabled)
|
||||
def test_google_search_is_kept_only_for_supported_nano_banana_models_when_true(self):
|
||||
for model in ("Nano Banana 2.1", "Nano Banana 2"):
|
||||
with self.subTest(model=model):
|
||||
enabled = JOBS.normalize_job_payload({**_payload(), "model": model, "google_search": True})
|
||||
self.assertIs(enabled["google_search"], True)
|
||||
disabled = JOBS.normalize_job_payload({**_payload(), "model": model, "google_search": False})
|
||||
self.assertNotIn("google_search", disabled)
|
||||
|
||||
unsupported = JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
@@ -307,6 +308,18 @@ class PayloadTests(unittest.TestCase):
|
||||
})
|
||||
self.assertNotIn("google_search", unsupported)
|
||||
|
||||
def test_nano_banana_21_accepts_every_route_and_extended_aspect_ratio(self):
|
||||
for route in ("畅速", "直连", "专线"):
|
||||
for ratio in ("1:4", "1:8", "4:1", "8:1"):
|
||||
with self.subTest(route=route, ratio=ratio):
|
||||
job = JOBS.normalize_job_payload({
|
||||
**_payload(), "model": "Nano Banana 2.1", "model_route": route,
|
||||
"aspect_ratio": ratio, "google_search": True,
|
||||
})
|
||||
self.assertEqual(job["model"], "Nano Banana 2.1")
|
||||
self.assertEqual(job["model_route"], route)
|
||||
self.assertIs(job["google_search"], True)
|
||||
|
||||
def test_batch_prompts_expand_prompt_major_and_enforce_total_limit(self):
|
||||
job = JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
@@ -997,7 +1010,7 @@ class NanoExecutionTests(unittest.IsolatedAsyncioTestCase):
|
||||
((0, 128, 0), (255, 255, 255)),
|
||||
])
|
||||
|
||||
async def test_references_are_reused_as_exact_inline_data_without_urls(self):
|
||||
async def test_nano_banana_21_reuses_inline_references_and_forwards_model_parameters(self):
|
||||
calls = []
|
||||
|
||||
class FakeHttpClient:
|
||||
@@ -1017,6 +1030,8 @@ class NanoExecutionTests(unittest.IsolatedAsyncioTestCase):
|
||||
Image.new("RGB", (5, 4), "orange").save(reference_path, format="JPEG")
|
||||
job = JOBS.normalize_job_payload({
|
||||
**_payload(),
|
||||
"model": "Nano Banana 2.1",
|
||||
"model_route": "专线",
|
||||
"prompt": "第一条\n---\n第二条",
|
||||
"image_count": 2,
|
||||
"google_search": True,
|
||||
@@ -1049,6 +1064,8 @@ class NanoExecutionTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(len(calls), 4)
|
||||
self.assertTrue(all(call["download_semaphore"] is None for call in calls))
|
||||
self.assertTrue(all(call["google_search"] is True for call in calls))
|
||||
self.assertTrue(all(call["model"] == "gemini-nano-banana-2.1" for call in calls))
|
||||
self.assertTrue(all(call["thinking_level"] == "high" for call in calls))
|
||||
self.assertEqual(
|
||||
[call["prompt"] for call in calls],
|
||||
["第一条", "第一条", "第二条", "第二条"],
|
||||
|
||||
Reference in New Issue
Block a user