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:
@@ -9,16 +9,17 @@ from .nano_banana_models import (
|
||||
|
||||
|
||||
GPT_IMAGE_MODEL_OPTIONS = [
|
||||
"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_MODEL_OPTIONS = ["Seedream 5.0 Pro"]
|
||||
UNIFIED_IMAGE_MODEL_OPTIONS = [
|
||||
*NANO_BANANA_MODEL_OPTIONS[:3],
|
||||
*GPT_IMAGE_MODEL_OPTIONS,
|
||||
*SEEDREAM_MODEL_OPTIONS,
|
||||
*NANO_BANANA_MODEL_OPTIONS[3:],
|
||||
]
|
||||
UNIFIED_IMAGE_ROUTE_OPTIONS = list(NANO_BANANA_ROUTE_OPTIONS)
|
||||
|
||||
@@ -65,8 +66,30 @@ GPT_IMAGE_EXACT_SIZE_OPTIONS = [
|
||||
]
|
||||
GPT_IMAGE_QUALITY_OPTIONS = ["高", "中", "低", "自动"]
|
||||
GPT_IMAGE_25_QUALITY_OPTIONS = [*GPT_IMAGE_QUALITY_OPTIONS, "超高", "最高"]
|
||||
GPT_IMAGE_OUTPUT_FORMAT_OPTIONS = ["jpeg", "png", "webp"]
|
||||
GPT_IMAGE_COMPLEXITY_OPTIONS = ["高", "中", "低"]
|
||||
GPT_IMAGE_COMPLEXITY_API_VALUES = ("low", "medium", "high")
|
||||
GPT_IMAGE_COMPLEXITY_LABEL_TO_API = {
|
||||
"高": "high",
|
||||
"中": "medium",
|
||||
"低": "low",
|
||||
"high": "high",
|
||||
"medium": "medium",
|
||||
"low": "low",
|
||||
}
|
||||
GPT_IMAGE_RASTER_OUTPUT_FORMAT_OPTIONS = ["jpeg", "png", "webp"]
|
||||
GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS = ["svg", "gif"]
|
||||
GPT_IMAGE_OUTPUT_FORMAT_OPTIONS = list(GPT_IMAGE_RASTER_OUTPUT_FORMAT_OPTIONS)
|
||||
GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS = [
|
||||
*GPT_IMAGE_RASTER_OUTPUT_FORMAT_OPTIONS,
|
||||
*GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS,
|
||||
]
|
||||
GPT_IMAGE_BACKGROUND_OPTIONS = ["auto", "transparent", "opaque"]
|
||||
GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT = 9
|
||||
GPT_IMAGE_GIF_FRAME_COUNT_MIN = 2
|
||||
GPT_IMAGE_GIF_FRAME_COUNT_MAX = 64
|
||||
GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT = 200
|
||||
GPT_IMAGE_GIF_FRAME_DURATION_MIN = 20
|
||||
GPT_IMAGE_GIF_FRAME_DURATION_MAX = 2000
|
||||
GPT_IMAGE_SIZE_MATRIX = {
|
||||
("1K", "1:1"): "1024x1024",
|
||||
("1K", "3:2"): "1536x1024",
|
||||
@@ -117,6 +140,80 @@ SEEDREAM_SIZE_MATRIX = {
|
||||
}
|
||||
|
||||
|
||||
|
||||
def is_gpt_image_26_model(model: str) -> bool:
|
||||
name = str(model or "").strip()
|
||||
if name in GPT_IMAGE_MODEL_OPTIONS:
|
||||
return name.startswith("gpt-image-2.6-")
|
||||
for base in GPT_IMAGE_MODEL_OPTIONS:
|
||||
if name in {base, f"{base}-sp", f"{base}-sd"}:
|
||||
return base.startswith("gpt-image-2.6-")
|
||||
return name.startswith("gpt-image-2.6-")
|
||||
|
||||
|
||||
def gpt_image_output_formats_for_model(model: str) -> list[str]:
|
||||
if is_gpt_image_26_model(model):
|
||||
return list(GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS)
|
||||
return list(GPT_IMAGE_RASTER_OUTPUT_FORMAT_OPTIONS)
|
||||
|
||||
|
||||
def resolve_gpt_image_output_format(model: str, output_format: str | None) -> str:
|
||||
value = str(output_format or "png").strip().lower()
|
||||
allowed = gpt_image_output_formats_for_model(model)
|
||||
if value not in allowed:
|
||||
if value in GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS:
|
||||
raise ValueError("SVG / GIF 输出仅支持 GPT Image 2.6 系列模型")
|
||||
raise ValueError("GPT Image 输出格式无效")
|
||||
return value
|
||||
|
||||
|
||||
def resolve_gpt_image_frame_count(output_format: str, frame_count=None) -> int | None:
|
||||
if str(output_format or "").strip().lower() != "gif":
|
||||
return None
|
||||
if frame_count is None or frame_count == "":
|
||||
return GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT
|
||||
try:
|
||||
value = int(frame_count)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValueError("GIF 帧数无效") from exc
|
||||
if value < GPT_IMAGE_GIF_FRAME_COUNT_MIN or value > GPT_IMAGE_GIF_FRAME_COUNT_MAX:
|
||||
raise ValueError(
|
||||
f"GIF 帧数仅支持 {GPT_IMAGE_GIF_FRAME_COUNT_MIN}–{GPT_IMAGE_GIF_FRAME_COUNT_MAX}"
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
def resolve_gpt_image_frame_duration_ms(output_format: str, frame_duration_ms=None) -> int | None:
|
||||
if str(output_format or "").strip().lower() != "gif":
|
||||
return None
|
||||
if frame_duration_ms is None or frame_duration_ms == "":
|
||||
value = GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT
|
||||
else:
|
||||
try:
|
||||
value = int(frame_duration_ms)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValueError("GIF 帧时长无效") from exc
|
||||
if value < GPT_IMAGE_GIF_FRAME_DURATION_MIN or value > GPT_IMAGE_GIF_FRAME_DURATION_MAX:
|
||||
raise ValueError(
|
||||
f"GIF 帧时长仅支持 {GPT_IMAGE_GIF_FRAME_DURATION_MIN}–{GPT_IMAGE_GIF_FRAME_DURATION_MAX} 毫秒"
|
||||
)
|
||||
return int(round(value / 10.0) * 10)
|
||||
|
||||
|
||||
def validate_gpt_image_vector_output(
|
||||
model: str,
|
||||
output_format: str,
|
||||
*,
|
||||
has_images: bool = False,
|
||||
has_mask: bool = False,
|
||||
) -> None:
|
||||
fmt = resolve_gpt_image_output_format(model, output_format)
|
||||
if fmt not in GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS:
|
||||
return
|
||||
if has_images or has_mask:
|
||||
raise ValueError("SVG / GIF 仅支持纯文生图,不能带参考图或蒙版")
|
||||
|
||||
|
||||
def is_gpt_image_model(model: str) -> bool:
|
||||
return model in GPT_IMAGE_MODEL_OPTIONS
|
||||
|
||||
@@ -124,8 +221,8 @@ def is_gpt_image_model(model: str) -> bool:
|
||||
def resolve_gpt_image_quality(model_name: str, quality: str) -> str:
|
||||
"""Resolve a displayed GPT quality for the selected model family."""
|
||||
if quality in {"超高", "最高"}:
|
||||
if model_name not in GPT_IMAGE_MODEL_OPTIONS or not model_name.startswith("gpt-image-2.5-"):
|
||||
raise ValueError("超高和最高质量仅支持 GPT Image 2.5 系列模型")
|
||||
if model_name not in GPT_IMAGE_MODEL_OPTIONS or not model_name.startswith(("gpt-image-2.5-", "gpt-image-2.6-")):
|
||||
raise ValueError("超高和最高质量仅支持 GPT Image 2.5 / 2.6 系列模型")
|
||||
return {"超高": "xhigh", "最高": "max"}[quality]
|
||||
try:
|
||||
return {"高": "high", "中": "medium", "低": "low", "自动": "auto"}[quality]
|
||||
@@ -133,6 +230,19 @@ def resolve_gpt_image_quality(model_name: str, quality: str) -> str:
|
||||
raise ValueError("GPT Image 质量参数无效") from None
|
||||
|
||||
|
||||
def resolve_gpt_image_complexity(model_name: str, complexity: str | None) -> str | None:
|
||||
"""Only 2.6 models send complexity; inactive controls retain their value."""
|
||||
if model_name not in GPT_IMAGE_MODEL_OPTIONS or not model_name.startswith("gpt-image-2.6-"):
|
||||
return None
|
||||
if complexity is None:
|
||||
return "high"
|
||||
raw = str(complexity).strip()
|
||||
value = GPT_IMAGE_COMPLEXITY_LABEL_TO_API.get(raw) or GPT_IMAGE_COMPLEXITY_LABEL_TO_API.get(raw.lower())
|
||||
if value not in GPT_IMAGE_COMPLEXITY_API_VALUES:
|
||||
raise ValueError("GPT Image 复杂度仅支持 低 / 中 / 高")
|
||||
return value
|
||||
|
||||
|
||||
def is_seedream_model(model: str) -> bool:
|
||||
return model in SEEDREAM_MODEL_OPTIONS
|
||||
|
||||
@@ -200,6 +310,10 @@ __all__ = [
|
||||
"GPT_IMAGE_ASPECT_RATIO_OPTIONS",
|
||||
"GPT_IMAGE_BACKGROUND_OPTIONS",
|
||||
"GPT_IMAGE_COUNTS",
|
||||
"GPT_IMAGE_COMPLEXITY_OPTIONS",
|
||||
"GPT_IMAGE_COMPLEXITY_API_VALUES",
|
||||
"GPT_IMAGE_COMPLEXITY_LABEL_TO_API",
|
||||
"resolve_gpt_image_complexity",
|
||||
"GPT_IMAGE_EXACT_SIZE_OPTIONS",
|
||||
"GPT_IMAGE_MODEL_OPTIONS",
|
||||
"GPT_IMAGE_25_QUALITY_OPTIONS",
|
||||
@@ -226,4 +340,19 @@ __all__ = [
|
||||
"resolve_gpt_image_quality",
|
||||
"resolve_seedream_size",
|
||||
"resolve_seedream_layer_size",
|
||||
"GPT_IMAGE_26_EXTRA_OUTPUT_FORMAT_OPTIONS",
|
||||
"GPT_IMAGE_26_OUTPUT_FORMAT_OPTIONS",
|
||||
"GPT_IMAGE_GIF_FRAME_COUNT_DEFAULT",
|
||||
"GPT_IMAGE_GIF_FRAME_COUNT_MAX",
|
||||
"GPT_IMAGE_GIF_FRAME_COUNT_MIN",
|
||||
"GPT_IMAGE_GIF_FRAME_DURATION_DEFAULT",
|
||||
"GPT_IMAGE_GIF_FRAME_DURATION_MAX",
|
||||
"GPT_IMAGE_GIF_FRAME_DURATION_MIN",
|
||||
"GPT_IMAGE_RASTER_OUTPUT_FORMAT_OPTIONS",
|
||||
"gpt_image_output_formats_for_model",
|
||||
"is_gpt_image_26_model",
|
||||
"resolve_gpt_image_frame_count",
|
||||
"resolve_gpt_image_frame_duration_ms",
|
||||
"resolve_gpt_image_output_format",
|
||||
"validate_gpt_image_vector_output",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user