Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(image-backends): align provider contracts and defaults

hugohe39de697b13d00
diff --git a/.env.example b/.env.example
index 689c12e4..593d806d 100644
--- a/.env.example
+++ b/.env.example
@@ -64,7 +64,7 @@
# ─────────────────────────────────────────────────────────────
# IMAGE_BACKEND=gemini
# GEMINI_API_KEY=your-gemini-api-key
-# GEMINI_MODEL=gemini-3.1-flash-image-preview
+# GEMINI_MODEL=gemini-3.1-flash-image
# GEMINI_BASE_URL=https://your-proxy-url.com
# ─────────────────────────────────────────────────────────────
@@ -84,7 +84,7 @@
# IMAGE_BACKEND=qwen
# QWEN_API_KEY=your-dashscope-key
# QWEN_MODEL=qwen-image-2.0-pro
-# QWEN_BASE_URL=https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
+# QWEN_BASE_URL=https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# ─────────────────────────────────────────────────────────────
# Example: Zhipu / 智谱生图示例
@@ -98,9 +98,9 @@
# Example: Volcengine / 火山引擎示例
# ─────────────────────────────────────────────────────────────
# IMAGE_BACKEND=volcengine
-# VOLCENGINE_API_KEY=your-volcengine-key
+# LAS_API_KEY=your-las-key
# VOLCENGINE_MODEL=doubao-seedream-4-5-251128
-# VOLCENGINE_BASE_URL=https://operator.las.cn-beijing.volces.com/api/v1/images/generations
+# VOLCENGINE_BASE_URL=https://operator.las.cn-beijing.volces.com/api/v1
# ─────────────────────────────────────────────────────────────
# Extended / Experimental backends
@@ -130,15 +130,15 @@
# SILICONFLOW_BASE_URL=https://api.siliconflow.cn/v1/images/generations
#
# FAL_KEY=your-fal-key
-# FAL_MODEL=fal-ai/imagen3/fast
+# FAL_MODEL=fal-ai/nano-banana-2
# FAL_BASE_URL=https://fal.run
#
# REPLICATE_API_TOKEN=r8_xxx
# REPLICATE_MODEL=black-forest-labs/flux-1.1-pro
-# REPLICATE_BASE_URL=https://api.replicate.com/v1/predictions
+# REPLICATE_BASE_URL=https://api.replicate.com/v1
#
# OPENROUTER_API_KEY=sk-or-v1-xxx
-# OPENROUTER_MODEL=google/gemini-3.1-flash-image-preview
+# OPENROUTER_MODEL=google/gemini-3.1-flash-image
# OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
#
# OpenAI-compatible example: Agnes AI / OpenAI-compatible 示例:Agnes AI
@@ -152,7 +152,7 @@
#
# IMAGE_BACKEND=modelscope
# MODELSCOPE_API_KEY=your-modelscope-key
-# MODELSCOPE_MODEL=Tongyi-MAI/Z-Image-Turbo
+# MODELSCOPE_MODEL=your-api-inference-text-to-image-model-id
# MODELSCOPE_BASE_URL=https://api-inference.modelscope.cn/v1
# ─────────────────────────────────────────────────────────────
@@ -163,7 +163,7 @@
# OPENAI_MODEL=gpt-image-2
# OPENAI_OUTPUT_FORMAT=png
# GEMINI_API_KEY=your-gemini-api-key
-# GEMINI_MODEL=gemini-3.1-flash-image-preview
+# GEMINI_MODEL=gemini-3.1-flash-image
#
# Switch providers by changing IMAGE_BACKEND only.
# 切换提供商时,只改 IMAGE_BACKEND 即可。
diff --git a/skills/ppt-master/.env.example b/skills/ppt-master/.env.example
index 6bcd1f81..f5af2d98 100644
--- a/skills/ppt-master/.env.example
+++ b/skills/ppt-master/.env.example
@@ -59,7 +59,7 @@
# ─────────────────────────────────────────────────────────────
# IMAGE_BACKEND=gemini
# GEMINI_API_KEY=your-gemini-api-key
-# GEMINI_MODEL=gemini-3.1-flash-image-preview
+# GEMINI_MODEL=gemini-3.1-flash-image
# GEMINI_BASE_URL=https://your-proxy-url.com
# ─────────────────────────────────────────────────────────────
@@ -79,7 +79,7 @@
# IMAGE_BACKEND=qwen
# QWEN_API_KEY=your-dashscope-key
# QWEN_MODEL=qwen-image-2.0-pro
-# QWEN_BASE_URL=https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
+# QWEN_BASE_URL=https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# ─────────────────────────────────────────────────────────────
# Example: Zhipu / 智谱生图示例
@@ -93,9 +93,9 @@
# Example: Volcengine / 火山引擎示例
# ─────────────────────────────────────────────────────────────
# IMAGE_BACKEND=volcengine
-# VOLCENGINE_API_KEY=your-volcengine-key
+# LAS_API_KEY=your-las-key
# VOLCENGINE_MODEL=doubao-seedream-4-5-251128
-# VOLCENGINE_BASE_URL=https://operator.las.cn-beijing.volces.com/api/v1/images/generations
+# VOLCENGINE_BASE_URL=https://operator.las.cn-beijing.volces.com/api/v1
# ─────────────────────────────────────────────────────────────
# Extended / Experimental backends
@@ -125,15 +125,15 @@
# SILICONFLOW_BASE_URL=https://api.siliconflow.cn/v1/images/generations
#
# FAL_KEY=your-fal-key
-# FAL_MODEL=fal-ai/imagen3/fast
+# FAL_MODEL=fal-ai/nano-banana-2
# FAL_BASE_URL=https://fal.run
#
# REPLICATE_API_TOKEN=r8_xxx
# REPLICATE_MODEL=black-forest-labs/flux-1.1-pro
-# REPLICATE_BASE_URL=https://api.replicate.com/v1/predictions
+# REPLICATE_BASE_URL=https://api.replicate.com/v1
#
# OPENROUTER_API_KEY=sk-or-v1-xxx
-# OPENROUTER_MODEL=google/gemini-3.1-flash-image-preview
+# OPENROUTER_MODEL=google/gemini-3.1-flash-image
# OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
#
# OpenAI-compatible example: Agnes AI / OpenAI-compatible 示例:Agnes AI
@@ -147,7 +147,7 @@
#
# IMAGE_BACKEND=modelscope
# MODELSCOPE_API_KEY=your-modelscope-key
-# MODELSCOPE_MODEL=Tongyi-MAI/Z-Image-Turbo
+# MODELSCOPE_MODEL=your-api-inference-text-to-image-model-id
# MODELSCOPE_BASE_URL=https://api-inference.modelscope.cn/v1
# ─────────────────────────────────────────────────────────────
@@ -158,7 +158,7 @@
# OPENAI_MODEL=gpt-image-2
# OPENAI_OUTPUT_FORMAT=png
# GEMINI_API_KEY=your-gemini-api-key
-# GEMINI_MODEL=gemini-3.1-flash-image-preview
+# GEMINI_MODEL=gemini-3.1-flash-image
#
# Switch providers by changing IMAGE_BACKEND only.
# 切换提供商时,只改 IMAGE_BACKEND 即可。
diff --git a/skills/ppt-master/references/image-generator.md b/skills/ppt-master/references/image-generator.md
index b5054e08..ca18f32c 100644
--- a/skills/ppt-master/references/image-generator.md
+++ b/skills/ppt-master/references/image-generator.md
@@ -619,7 +619,7 @@ The CLI validates the file behind every `Generated` row before skipping it, iter
|---|---|---|---|
| `--manifest` | - | Path to `image_prompts.json` | — |
| `--concurrency` | - | Max concurrent requests; halves on rate-limit, min 1 | `IMAGE_CONCURRENCY` env or `3` |
-| `--image_size` | - | Default size (`512px`/`1K`/`2K`/`4K`); per-item `image_size` wins | `1K` |
+| `--image_size` | - | Default size (`512px`/`1K`/`2K`/`4K`); per-item `image_size` wins | Backend default; see `--list-backends` |
| `--output` | `-o` | Output directory | Manifest's parent dir |
| `--backend` | `-b` | Override `IMAGE_BACKEND` for this run | env |
| `--model` | `-m` | Default model; per-item `model` wins | Backend default |
diff --git a/skills/ppt-master/scripts/image_backends/backend_bfl.py b/skills/ppt-master/scripts/image_backends/backend_bfl.py
index d553365b..ee9fbe09 100644
--- a/skills/ppt-master/scripts/image_backends/backend_bfl.py
+++ b/skills/ppt-master/scripts/image_backends/backend_bfl.py
@@ -34,6 +34,7 @@ from image_backends.backend_common import (
download_image,
http_error,
is_rate_limit_error,
+ normalize_image_size,
poll_json,
require_api_key,
resolve_output_path,
@@ -57,18 +58,43 @@ MODEL_ENDPOINTS = {
ASPECT_RATIO_TO_DIMENSIONS = {
"1:1": (1024, 1024),
- "2:3": (1024, 1536),
- "3:2": (1536, 1024),
- "3:4": (1024, 1365),
- "4:3": (1365, 1024),
+ "2:3": (960, 1440),
+ "3:2": (1440, 960),
+ "3:4": (1056, 1408),
+ "4:3": (1408, 1056),
"4:5": (1024, 1280),
"5:4": (1280, 1024),
- "9:16": (1024, 1820),
- "16:9": (1820, 1024),
- "21:9": (2048, 878),
+ "9:16": (576, 1024),
+ "16:9": (1024, 576),
+ "21:9": (1344, 576),
}
+def _resolve_request_options(
+ aspect_ratio: str,
+ image_size: str,
+ model: str,
+) -> tuple[str, str]:
+ """Validate request options and return the normalized model and endpoint."""
+ if aspect_ratio not in VALID_ASPECT_RATIOS:
+ raise ValueError(
+ f"Unsupported aspect ratio '{aspect_ratio}' for BFL backend. "
+ f"Supported: {VALID_ASPECT_RATIOS}"
+ )
+ normalized_model = model.strip().lower()
+ endpoint = MODEL_ENDPOINTS.get(normalized_model)
+ if not endpoint:
+ supported = sorted(MODEL_ENDPOINTS)
+ raise ValueError(f"Unsupported BFL model '{model}'. Supported: {supported}")
+ normalized_size = normalize_image_size(image_size)
+ if normalized_size != "1K":
+ raise ValueError(
+ f"BFL model '{normalized_model}' does not expose the unified image_size preset; "
+ f"only the default '1K' is supported, got '{image_size}'."
+ )
+ return normalized_model, endpoint
+
+
def _submit_request(url: str, headers: dict, payload: dict) -> dict:
"""Submit a BFL generation request and return the JSON response."""
response = requests.post(url, headers=headers, json=payload, timeout=180)
@@ -82,19 +108,11 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_BASE_URL) -> str:
"""Generate one image with the Black Forest Labs backend."""
- del image_size # BFL quality is primarily controlled by model choice.
-
- if aspect_ratio not in VALID_ASPECT_RATIOS:
- raise ValueError(
- f"Unsupported aspect ratio '{aspect_ratio}' for BFL backend. "
- f"Supported: {VALID_ASPECT_RATIOS}"
- )
-
- normalized_model = model.strip().lower()
- endpoint = MODEL_ENDPOINTS.get(normalized_model)
- if not endpoint:
- supported = sorted(MODEL_ENDPOINTS)
- raise ValueError(f"Unsupported BFL model '{model}'. Supported: {supported}")
+ normalized_model, endpoint = _resolve_request_options(
+ aspect_ratio,
+ image_size,
+ model,
+ )
headers = {
"x-key": api_key,
@@ -139,7 +157,13 @@ def _generate_image(api_key: str, prompt: str,
{"x-key": api_key, "accept": "application/json"},
status_label="status",
ready_values=["Ready"],
- failed_values=["Error", "Failed", "Request Moderated", "Content Moderated"],
+ failed_values=[
+ "Error",
+ "Failed",
+ "Task not found",
+ "Request Moderated",
+ "Content Moderated",
+ ],
)
image_url = ((result_payload.get("result") or {}).get("sample"))
@@ -155,12 +179,13 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the BFL backend."""
+ resolved_model = model or os.environ.get("BFL_MODEL") or DEFAULT_MODEL
+ _resolve_request_options(aspect_ratio, image_size, resolved_model)
api_key = require_api_key(
"BFL_API_KEY",
message="No API key found. Set BFL_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("BFL_BASE_URL") or DEFAULT_BASE_URL
- resolved_model = model or os.environ.get("BFL_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_fal.py b/skills/ppt-master/scripts/image_backends/backend_fal.py
index 0551960f..7e05bc7a 100644
--- a/skills/ppt-master/scripts/image_backends/backend_fal.py
+++ b/skills/ppt-master/scripts/image_backends/backend_fal.py
@@ -5,7 +5,7 @@ fal.ai image generation backend.
Configuration keys:
FAL_KEY / FAL_API_KEY (required)
FAL_BASE_URL (optional)
- FAL_MODEL (optional)
+ FAL_MODEL (optional; nano-banana-2 only)
"""
import sys
@@ -34,15 +34,53 @@ from image_backends.backend_common import (
download_image,
http_error,
is_rate_limit_error,
+ normalize_image_size,
require_api_key,
resolve_output_path,
retry_delay,
)
-VALID_ASPECT_RATIOS = ["1:1", "16:9", "9:16", "3:4", "4:3"]
+VALID_ASPECT_RATIOS = [
+ "1:1", "1:4", "1:8", "2:3", "3:2", "3:4", "4:1",
+ "4:3", "4:5", "5:4", "8:1", "9:16", "16:9", "21:9",
+]
DEFAULT_ENDPOINT = "https://fal.run"
-DEFAULT_MODEL = "fal-ai/imagen3/fast"
+DEFAULT_MODEL = "fal-ai/nano-banana-2"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
+
+IMAGE_SIZE_TO_RESOLUTION = {
+ "512px": "0.5K",
+ "1K": "1K",
+ "2K": "2K",
+ "4K": "4K",
+}
+
+
+def _resolve_request_options(
+ aspect_ratio: str,
+ image_size: str,
+ model: str,
+) -> tuple[str, str]:
+ """Validate request options and return normalized model and resolution values."""
+ resolved_model = model.strip()
+ if resolved_model not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported fal model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ if aspect_ratio not in VALID_ASPECT_RATIOS:
+ raise ValueError(
+ f"Unsupported aspect ratio '{aspect_ratio}' for fal backend. "
+ f"Supported: {VALID_ASPECT_RATIOS}"
+ )
+ normalized_size = normalize_image_size(image_size)
+ resolution = IMAGE_SIZE_TO_RESOLUTION.get(normalized_size)
+ if not resolution:
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for fal backend. "
+ f"Supported: {list(IMAGE_SIZE_TO_RESOLUTION)}"
+ )
+ return resolved_model, resolution
def _resolve_url(base_url: str, model: str) -> str:
@@ -58,13 +96,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the fal.ai backend."""
- del image_size
-
- if aspect_ratio not in VALID_ASPECT_RATIOS:
- raise ValueError(
- f"Unsupported aspect ratio '{aspect_ratio}' for fal backend. "
- f"Supported: {VALID_ASPECT_RATIOS}"
- )
+ model, resolution = _resolve_request_options(aspect_ratio, image_size, model)
url = _resolve_url(base_url, model)
headers = {
@@ -75,12 +107,14 @@ def _generate_image(api_key: str, prompt: str,
"prompt": prompt,
"aspect_ratio": aspect_ratio,
"num_images": 1,
+ "resolution": resolution,
}
print("[fal.ai]")
print(f" Model: {model}")
print(f" Prompt: {prompt[:120]}{'...' if len(prompt) > 120 else ''}")
print(f" Aspect Ratio: {aspect_ratio}")
+ print(f" Resolution: {resolution}")
print()
print(" [..] Generating...", end="", flush=True)
start = time.time()
@@ -106,13 +140,14 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the fal.ai backend."""
+ resolved_model = model or os.environ.get("FAL_MODEL") or DEFAULT_MODEL
+ _resolve_request_options(aspect_ratio, image_size, resolved_model)
api_key = require_api_key(
"FAL_KEY",
"FAL_API_KEY",
message="No API key found. Set FAL_KEY or FAL_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("FAL_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("FAL_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_gemini.py b/skills/ppt-master/scripts/image_backends/backend_gemini.py
index 3f56e8bc..2511b9c6 100644
--- a/skills/ppt-master/scripts/image_backends/backend_gemini.py
+++ b/skills/ppt-master/scripts/image_backends/backend_gemini.py
@@ -57,7 +57,48 @@ VALID_ASPECT_RATIOS = [
VALID_IMAGE_SIZES = ["512px", "1K", "2K", "4K"]
-DEFAULT_MODEL = "gemini-3.1-flash-image-preview"
+DEFAULT_MODEL = "gemini-3.1-flash-image"
+
+GEMINI_2_5_FLASH_IMAGE_MODELS = {
+ "gemini-2.5-flash-image",
+ "gemini-2.5-flash-image-preview",
+}
+GEMINI_2_5_VALID_ASPECT_RATIOS = [
+ "1:1", "2:3", "3:2", "3:4", "4:3",
+ "4:5", "5:4", "9:16", "16:9", "21:9",
+]
+GEMINI_2_5_VALID_IMAGE_SIZES = ["1K"]
+
+MINIMAL_THINKING_MODELS = {
+ "gemini-3.1-flash-image",
+ "gemini-3.1-flash-image-preview",
+}
+
+
+def _model_id(model: str) -> str:
+ """Return the final model path component for official capability checks."""
+ return (model or "").strip().lower().rsplit("/", 1)[-1]
+
+
+def _request_image_size(image_size: str) -> str:
+ """Map the public 512px preset to Gemini's API value."""
+ return "512" if image_size == "512px" else image_size
+
+
+def _validate_model_options(model: str, aspect_ratio: str, image_size: str) -> None:
+ """Enforce limits only for Gemini models with a known narrower contract."""
+ if _model_id(model) not in GEMINI_2_5_FLASH_IMAGE_MODELS:
+ return
+ if aspect_ratio not in GEMINI_2_5_VALID_ASPECT_RATIOS:
+ raise ValueError(
+ f"Invalid aspect ratio '{aspect_ratio}' for {model}. "
+ f"Valid: {GEMINI_2_5_VALID_ASPECT_RATIOS}"
+ )
+ if image_size not in GEMINI_2_5_VALID_IMAGE_SIZES:
+ raise ValueError(
+ f"Invalid image size '{image_size}' for {model}. "
+ f"Valid: {GEMINI_2_5_VALID_IMAGE_SIZES}"
+ )
# ╔══════���═══════════════════════════════════════════════��═══════════╗
@@ -86,10 +127,10 @@ def _generate_image(api_key: str, prompt: str,
"response_modalities": ["IMAGE"],
"image_config": types.ImageConfig(
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=_request_image_size(image_size),
),
}
- if "flash" in model.lower():
+ if _model_id(model) in MINIMAL_THINKING_MODELS:
config_kwargs["thinking_config"] = types.ThinkingConfig(
thinking_level="MINIMAL",
)
@@ -186,7 +227,7 @@ def generate(prompt: str,
image_size: Image size ("512px", "1K", "2K", "4K", case-insensitive)
output_dir: Output directory
filename: Output filename (without extension)
- model: Model name (default: gemini-3.1-flash-image-preview)
+ model: Model name (default: gemini-3.1-flash-image)
max_retries: Maximum number of retries
Returns:
@@ -211,6 +252,8 @@ def generate(prompt: str,
if image_size not in VALID_IMAGE_SIZES:
raise ValueError(f"Invalid image size '{image_size}'. Valid: {VALID_IMAGE_SIZES}")
+ _validate_model_options(model, aspect_ratio, image_size)
+
last_error = None
for attempt in range(max_retries + 1):
try:
diff --git a/skills/ppt-master/scripts/image_backends/backend_ideogram.py b/skills/ppt-master/scripts/image_backends/backend_ideogram.py
index 189d5401..ab11e67a 100644
--- a/skills/ppt-master/scripts/image_backends/backend_ideogram.py
+++ b/skills/ppt-master/scripts/image_backends/backend_ideogram.py
@@ -34,6 +34,7 @@ from image_backends.backend_common import (
download_image,
http_error,
is_rate_limit_error,
+ normalize_image_size,
require_api_key,
resolve_output_path,
retry_delay,
@@ -42,29 +43,53 @@ from image_backends.backend_common import (
ASPECT_RATIO_MAP = {
"1:1": "1x1",
- "1:4": "1x4",
+ "1:2": "1x2",
+ "1:3": "1x3",
+ "2:1": "2x1",
"2:3": "2x3",
+ "3:1": "3x1",
"3:2": "3x2",
"3:4": "3x4",
- "4:1": "4x1",
"4:3": "4x3",
"4:5": "4x5",
"5:4": "5x4",
"9:16": "9x16",
+ "10:16": "10x16",
"16:9": "16x9",
- "21:9": "21x9",
+ "16:10": "16x10",
}
DEFAULT_BASE_URL = "https://api.ideogram.ai"
DEFAULT_MODEL = "ideogram-v3"
MODEL_ALIASES = {"ideogram-v3", "v3"}
-IMAGE_SIZE_TO_SPEED = {
- "512px": "TURBO",
- "1K": "DEFAULT",
- "2K": "QUALITY",
- "4K": "QUALITY",
-}
+DEFAULT_RENDERING_SPEED = "DEFAULT"
+
+
+def _resolve_request_options(
+ aspect_ratio: str,
+ image_size: str,
+ model: str,
+) -> tuple[str, str]:
+ """Validate request options and return normalized model and ratio values."""
+ normalized_model = model.strip().lower()
+ if normalized_model not in MODEL_ALIASES:
+ raise ValueError(
+ f"Unsupported Ideogram model '{model}'. Supported: {sorted(MODEL_ALIASES)}"
+ )
+ mapped_ratio = ASPECT_RATIO_MAP.get(aspect_ratio)
+ if not mapped_ratio:
+ raise ValueError(
+ f"Unsupported aspect ratio '{aspect_ratio}' for Ideogram backend. "
+ f"Supported: {sorted(ASPECT_RATIO_MAP)}"
+ )
+ normalized_size = normalize_image_size(image_size)
+ if normalized_size != "1K":
+ raise ValueError(
+ "Ideogram V3 aspect-ratio generation only supports the default '1K' preset; "
+ f"got '{image_size}'."
+ )
+ return normalized_model, mapped_ratio
def _resolve_url(base_url: str) -> str:
@@ -80,33 +105,25 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_BASE_URL) -> str:
"""Generate one image with the Ideogram backend."""
- normalized_model = model.strip().lower()
- if normalized_model not in MODEL_ALIASES:
- raise ValueError(
- f"Unsupported Ideogram model '{model}'. Supported: {sorted(MODEL_ALIASES)}"
- )
-
- mapped_ratio = ASPECT_RATIO_MAP.get(aspect_ratio)
- if not mapped_ratio:
- raise ValueError(
- f"Unsupported aspect ratio '{aspect_ratio}' for Ideogram backend. "
- f"Supported: {sorted(ASPECT_RATIO_MAP)}"
- )
+ normalized_model, mapped_ratio = _resolve_request_options(
+ aspect_ratio,
+ image_size,
+ model,
+ )
- rendering_speed = IMAGE_SIZE_TO_SPEED.get(image_size, "DEFAULT")
url = _resolve_url(base_url)
headers = {"Api-Key": api_key}
files = {
"prompt": (None, prompt),
"aspect_ratio": (None, mapped_ratio),
- "rendering_speed": (None, rendering_speed),
+ "rendering_speed": (None, DEFAULT_RENDERING_SPEED),
}
print("[Ideogram]")
print(f" Model: {normalized_model}")
print(f" Prompt: {prompt[:120]}{'...' if len(prompt) > 120 else ''}")
print(f" Aspect Ratio: {aspect_ratio} -> {mapped_ratio}")
- print(f" Render Speed: {rendering_speed}")
+ print(f" Render Speed: {DEFAULT_RENDERING_SPEED}")
print()
print(" [..] Generating...", end="", flush=True)
start = time.time()
@@ -132,12 +149,13 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Ideogram backend."""
+ resolved_model = model or os.environ.get("IDEOGRAM_MODEL") or DEFAULT_MODEL
+ _resolve_request_options(aspect_ratio, image_size, resolved_model)
api_key = require_api_key(
"IDEOGRAM_API_KEY",
message="No API key found. Set IDEOGRAM_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("IDEOGRAM_BASE_URL") or DEFAULT_BASE_URL
- resolved_model = model or os.environ.get("IDEOGRAM_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_minimax.py b/skills/ppt-master/scripts/image_backends/backend_minimax.py
index ea5bf6b2..6a3fd2f2 100644
--- a/skills/ppt-master/scripts/image_backends/backend_minimax.py
+++ b/skills/ppt-master/scripts/image_backends/backend_minimax.py
@@ -5,7 +5,7 @@ MiniMax image generation backend.
Configuration keys:
MINIMAX_API_KEY (required)
MINIMAX_BASE_URL (optional)
- MINIMAX_MODEL (optional)
+ MINIMAX_MODEL (optional; image-01 only)
"""
import sys
@@ -45,19 +45,20 @@ from image_backends.backend_common import (
DEFAULT_ENDPOINT = "https://api.minimaxi.com/v1/image_generation"
DEFAULT_MODEL = "image-01"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
# International fallback: set MINIMAX_BASE_URL=https://api.minimax.io if needed
ASPECT_RATIO_SIZE_MAP = {
"512px": {
"1:1": (512, 512),
- "16:9": (640, 360),
- "4:3": (576, 432),
- "3:2": (624, 416),
- "2:3": (416, 624),
- "3:4": (432, 576),
- "9:16": (360, 640),
- "21:9": (672, 288),
+ "16:9": (912, 512),
+ "4:3": (680, 512),
+ "3:2": (768, 512),
+ "2:3": (512, 768),
+ "3:4": (512, 680),
+ "9:16": (512, 912),
+ "21:9": (1192, 512),
},
"1K": {
"1:1": (1024, 1024),
@@ -79,19 +80,19 @@ ASPECT_RATIO_SIZE_MAP = {
"9:16": (1152, 2048),
"21:9": (2048, 880),
},
- "4K": {
- "1:1": (2048, 2048),
- "16:9": (2048, 1152),
- "4:3": (2048, 1536),
- "3:2": (2048, 1368),
- "2:3": (1368, 2048),
- "3:4": (1536, 2048),
- "9:16": (1152, 2048),
- "21:9": (2048, 880),
- },
}
+def _validate_model(model: str) -> str:
+ """Limit the backend to the model contract implemented below."""
+ resolved = model.strip()
+ if resolved not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported MiniMax model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ return resolved
+
+
def _resolve_url(base_url: str) -> str:
"""Resolve the MiniMax image generation endpoint.
@@ -111,9 +112,16 @@ def _resolve_url(base_url: str) -> str:
def _resolve_dimensions(aspect_ratio: str, image_size: str) -> tuple[int, int]:
"""Resolve width and height from the unified aspect_ratio/image_size pair."""
normalized = normalize_image_size(image_size)
- dimensions = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)
+ sizes = ASPECT_RATIO_SIZE_MAP.get(normalized)
+ if sizes is None:
+ supported_sizes = ", ".join(ASPECT_RATIO_SIZE_MAP)
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for MiniMax backend. "
+ f"image-01 supports these logical sizes: {supported_sizes}."
+ )
+ dimensions = sizes.get(aspect_ratio)
if not dimensions:
- supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])
+ supported = sorted(sizes)
raise ValueError(
f"Unsupported aspect ratio '{aspect_ratio}' for MiniMax backend. "
f"Supported: {supported}"
@@ -135,6 +143,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the MiniMax backend."""
+ model = _validate_model(model)
width, height = _resolve_dimensions(aspect_ratio, image_size)
url = _resolve_url(base_url)
@@ -185,13 +194,15 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the MiniMax backend."""
+ resolved_model = model or os.environ.get("MINIMAX_MODEL") or DEFAULT_MODEL
+ _validate_model(resolved_model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_dimensions(aspect_ratio, normalized_size)
api_key = require_api_key(
"MINIMAX_API_KEY",
message="No API key found. Set MINIMAX_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("MINIMAX_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("MINIMAX_MODEL") or DEFAULT_MODEL
- normalized_size = normalize_image_size(image_size)
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_modelscope.py b/skills/ppt-master/scripts/image_backends/backend_modelscope.py
index 04243e90..434e7905 100644
--- a/skills/ppt-master/scripts/image_backends/backend_modelscope.py
+++ b/skills/ppt-master/scripts/image_backends/backend_modelscope.py
@@ -4,7 +4,7 @@ ModelScope image generation backend.
Configuration keys:
MODELSCOPE_API_KEY (required)
- MODELSCOPE_MODEL (optional)
+ MODELSCOPE_MODEL (required; no static default)
MODELSCOPE_BASE_URL (optional)
"""
@@ -26,7 +26,6 @@ from image_backends.backend_common import (
)
DEFAULT_ENDPOINT = "https://api-inference.modelscope.cn"
-DEFAULT_MODEL = "Tongyi-MAI/Z-Image-Turbo"
# Resolution must be 64-aligned.
ASPECT_RATIO_SIZE_MAP = {
@@ -85,11 +84,29 @@ def _resolve_size(aspect_ratio: str, image_size: str) -> str:
return size
+def _resolve_model(model: str = None) -> str:
+ """Require an explicitly configured text-to-image API-Inference model."""
+ resolved = (model or os.environ.get("MODELSCOPE_MODEL") or "").strip()
+ if not resolved:
+ raise ValueError(
+ "No ModelScope text-to-image model configured. Pass model=... or set "
+ "MODELSCOPE_MODEL to a current API-Inference text-to-image model from "
+ "https://api-inference.modelscope.cn/v1/models."
+ )
+ if "edit" in resolved.lower():
+ raise ValueError(
+ "ModelScope image-edit models require source images and are not supported "
+ "by this text-to-image backend."
+ )
+ return resolved
+
+
def _generate_image(api_key: str, prompt: str,
aspect_ratio: str = "1:1", image_size: str = "1K",
output_dir: str = None, filename: str = None,
- model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
+ model: str = None, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the ModelScope backend."""
+ resolved_model = _resolve_model(model)
size = _resolve_size(aspect_ratio, image_size)
url = _resolve_url(base_url)+'/v1/images/generations'
common_headers = {
@@ -97,14 +114,14 @@ def _generate_image(api_key: str, prompt: str,
"Content-Type": "application/json",
}
payload = {
- "model": model,
+ "model": resolved_model,
"prompt": prompt,
"size": size.replace("*", "x"),
}
print("[ModelScope Models]")
- print(f" Model: {model}")
+ print(f" Model: {resolved_model}")
print(f" Prompt: {prompt[:120]}{'...' if len(prompt) > 120 else ''}")
print(f" Aspect Ratio: {aspect_ratio}")
print(f" Resolution: {size}")
@@ -134,12 +151,14 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the ModelScope backend."""
+ resolved_model = _resolve_model(model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_size(aspect_ratio, normalized_size)
api_key = require_api_key(
"MODELSCOPE_API_KEY",
message="No API key found. Set MODELSCOPE_API_KEY in the current environment or the project-root .env.",
)
base_url = os.environ.get("MODELSCOPE_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("MODELSCOPE_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
@@ -148,7 +167,7 @@ def generate(prompt: str,
api_key=api_key,
prompt=prompt,
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=normalized_size,
output_dir=output_dir,
filename=filename,
model=resolved_model,
@@ -165,4 +184,3 @@ def generate(prompt: str,
time.sleep(delay)
raise RuntimeError(f"Failed after {max_retries + 1} attempts. Last error: {last_error}")
-
diff --git a/skills/ppt-master/scripts/image_backends/backend_openai.py b/skills/ppt-master/scripts/image_backends/backend_openai.py
index aa6918fb..ca624632 100644
--- a/skills/ppt-master/scripts/image_backends/backend_openai.py
+++ b/skills/ppt-master/scripts/image_backends/backend_openai.py
@@ -342,12 +342,17 @@ def _read_response_format() -> str | None:
return _read_env_choice("OPENAI_RESPONSE_FORMAT", OPENAI_RESPONSE_FORMATS)
-def _read_quality(image_size: str) -> str | None:
+def _read_quality(image_size: str, model: str) -> str | None:
"""Resolve the quality field for OpenAI-compatible requests."""
quality = _read_env_choice("OPENAI_QUALITY", OPENAI_QUALITY_VALUES)
if quality == "omit":
return None
if quality and quality != "auto":
+ if _is_gpt_image_model(model) and quality in {"standard", "hd"}:
+ raise ValueError(
+ f"{model} does not support OPENAI_QUALITY={quality}. "
+ "Use auto, omit, low, medium, or high."
+ )
return quality
return IMAGE_SIZE_TO_QUALITY.get(image_size, "auto")
@@ -357,11 +362,34 @@ def _apply_response_format(request: dict, model: str) -> None:
response_format = _read_response_format()
if response_format == "omit":
return
+ if not _supports_response_format(model):
+ if response_format in {"b64_json", "url"}:
+ raise ValueError(
+ f"{model} does not support OPENAI_RESPONSE_FORMAT. "
+ "Use auto or omit."
+ )
+ return
if response_format in {"b64_json", "url"}:
request["response_format"] = response_format
return
- if _supports_response_format(model):
- request["response_format"] = "b64_json"
+ request["response_format"] = "b64_json"
+
+
+def _validate_request_options(
+ model: str,
+ aspect_ratio: str,
+ image_size: str,
+ *,
+ editing: bool,
+) -> None:
+ """Validate local model options before entering the retry loop."""
+ size_preset = _read_size_preset()
+ _select_size(model, aspect_ratio, image_size, size_preset)
+ if not (editing and _is_dall_e_2(model)):
+ _read_quality(image_size, model)
+ if _is_gpt_image_model(model):
+ _gpt_image_options(model)
+ _apply_response_format({}, model)
def _post_image_generation(api_key: str, base_url: str | None, request: dict) -> dict:
@@ -431,7 +459,7 @@ def _generate_image(api_key: str, prompt: str,
# Map parameters
size_preset = _read_size_preset()
size = _select_size(model, aspect_ratio, image_size, size_preset)
- quality = _read_quality(image_size)
+ quality = _read_quality(image_size, model)
output_ext = ".png"
request = {
"prompt": prompt,
@@ -527,7 +555,7 @@ def _edit_image(api_key: str, prompt: str, reference_image: str,
"""
size_preset = _read_size_preset()
size = _select_size(model, aspect_ratio, image_size, size_preset)
- quality = None if _is_dall_e_2(model) else _read_quality(image_size)
+ quality = None if _is_dall_e_2(model) else _read_quality(image_size, model)
output_ext = ".png"
request = {
"prompt": prompt,
@@ -640,14 +668,6 @@ def generate(prompt: str,
Returns:
Path of the saved image file
"""
- api_key = os.environ.get("OPENAI_API_KEY")
- base_url = os.environ.get("OPENAI_BASE_URL")
-
- if not api_key:
- raise ValueError(
- "No API key found. Set OPENAI_API_KEY in the current environment or a .env file."
- )
-
if model is None:
model = os.environ.get("OPENAI_MODEL") or DEFAULT_MODEL
@@ -660,6 +680,20 @@ def generate(prompt: str,
f"Supported: {supported}"
)
+ _validate_request_options(
+ model,
+ aspect_ratio,
+ image_size,
+ editing=reference_image is not None,
+ )
+
+ api_key = os.environ.get("OPENAI_API_KEY")
+ base_url = os.environ.get("OPENAI_BASE_URL")
+ if not api_key:
+ raise ValueError(
+ "No API key found. Set OPENAI_API_KEY in the current environment or a .env file."
+ )
+
last_error = None
for attempt in range(max_retries + 1):
try:
diff --git a/skills/ppt-master/scripts/image_backends/backend_openrouter.py b/skills/ppt-master/scripts/image_backends/backend_openrouter.py
index c0851b45..7efc4df3 100644
--- a/skills/ppt-master/scripts/image_backends/backend_openrouter.py
+++ b/skills/ppt-master/scripts/image_backends/backend_openrouter.py
@@ -33,6 +33,7 @@ from image_backends.backend_common import (
MAX_RETRIES,
decode_data_uri,
find_data_uri,
+ http_error,
is_rate_limit_error,
normalize_image_size,
resolve_output_path,
@@ -51,9 +52,9 @@ VALID_ASPECT_RATIOS = [
"4:5", "5:4", "8:1", "9:16", "16:9", "21:9"
]
-VALID_IMAGE_SIZES = ["1K", "2K", "4K", "0.5K"]
+VALID_IMAGE_SIZES = ["512px", "1K", "2K", "4K"]
-DEFAULT_MODEL = "google/gemini-3.1-flash-image-preview"
+DEFAULT_MODEL = "google/gemini-3.1-flash-image"
DEFAULT_ENDPOINT = "https://openrouter.ai/api/v1"
# ╔══════════════════════════════════════════════════════════════════╗
@@ -108,7 +109,7 @@ def _generate_image(api_key: str, prompt: str,
"modalities": ["image", "text"],
"image_config": {
"aspect_ratio": aspect_ratio,
- "image_size": image_size
+ "image_size": "512" if image_size == "512px" else image_size
}
}
@@ -136,7 +137,10 @@ def _generate_image(api_key: str, prompt: str,
hb_thread.start()
try:
- result = requests.post(url, headers=headers, json=payload, timeout=300).json()
+ response = requests.post(url, headers=headers, json=payload, timeout=300)
+ if response.status_code != 200:
+ raise http_error(response, "OpenRouter image generation")
+ result = response.json()
finally:
heartbeat_stop.set()
hb_thread.join(timeout=1)
@@ -172,7 +176,7 @@ def generate(prompt: str,
OPENROUTER_MODEL (optional override)
"""
api_key = os.environ.get("OPENROUTER_API_KEY")
- base_url = os.environ.get("OPENROUTER_BASE_URL")
+ base_url = os.environ.get("OPENROUTER_BASE_URL") or DEFAULT_ENDPOINT
if not api_key:
raise ValueError(
diff --git a/skills/ppt-master/scripts/image_backends/backend_qwen.py b/skills/ppt-master/scripts/image_backends/backend_qwen.py
index 7c4e19dc..06935376 100644
--- a/skills/ppt-master/scripts/image_backends/backend_qwen.py
+++ b/skills/ppt-master/scripts/image_backends/backend_qwen.py
@@ -5,7 +5,7 @@ Alibaba Cloud Qwen image generation backend.
Configuration keys:
QWEN_API_KEY / DASHSCOPE_API_KEY (required)
QWEN_BASE_URL (optional)
- QWEN_MODEL (optional)
+ QWEN_MODEL (optional; qwen-image-2.0-pro only)
"""
import sys
@@ -43,6 +43,7 @@ from image_backends.backend_common import (
DEFAULT_ENDPOINT = "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
DEFAULT_MODEL = "qwen-image-2.0-pro"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
ASPECT_RATIO_SIZE_MAP = {
"512px": {
@@ -81,35 +82,42 @@ ASPECT_RATIO_SIZE_MAP = {
"16:9": "2688*1536",
"21:9": "2688*1152",
},
- "4K": {
- "1:1": "2048*2048",
- "2:3": "1536*2048",
- "3:2": "2048*1536",
- "3:4": "1728*2368",
- "4:3": "2368*1728",
- "4:5": "1792*2240",
- "5:4": "2240*1792",
- "9:16": "1536*2688",
- "16:9": "2688*1536",
- "21:9": "2688*1152",
- },
}
+def _validate_model(model: str) -> str:
+ """Limit the backend to the model contract implemented below."""
+ resolved = model.strip()
+ if resolved not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported Qwen model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ return resolved
+
+
def _resolve_url(base_url: str) -> str:
"""Resolve the Qwen generation endpoint."""
base = base_url.rstrip("/")
if base.endswith("/generation"):
return base
+ if base.endswith("/api/v1"):
+ return base + "/services/aigc/multimodal-generation/generation"
return base + "/api/v1/services/aigc/multimodal-generation/generation"
def _resolve_size(aspect_ratio: str, image_size: str) -> str:
"""Resolve the target resolution for a ratio and logical size preset."""
normalized = normalize_image_size(image_size)
- size = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)
+ sizes = ASPECT_RATIO_SIZE_MAP.get(normalized)
+ if sizes is None:
+ supported_sizes = ", ".join(ASPECT_RATIO_SIZE_MAP)
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for Qwen backend. "
+ f"qwen-image-2.0-pro supports these logical sizes: {supported_sizes}."
+ )
+ size = sizes.get(aspect_ratio)
if not size:
- supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])
+ supported = sorted(sizes)
raise ValueError(
f"Unsupported aspect ratio '{aspect_ratio}' for Qwen backend. "
f"Supported: {supported}"
@@ -122,6 +130,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the Qwen backend."""
+ model = _validate_model(model)
size = _resolve_size(aspect_ratio, image_size)
url = _resolve_url(base_url)
headers = {
@@ -176,13 +185,16 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Qwen backend."""
+ resolved_model = model or os.environ.get("QWEN_MODEL") or DEFAULT_MODEL
+ _validate_model(resolved_model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_size(aspect_ratio, normalized_size)
api_key = require_api_key(
"QWEN_API_KEY",
"DASHSCOPE_API_KEY",
message="No API key found. Set QWEN_API_KEY or DASHSCOPE_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("QWEN_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("QWEN_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
@@ -191,7 +203,7 @@ def generate(prompt: str,
api_key=api_key,
prompt=prompt,
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=normalized_size,
output_dir=output_dir,
filename=filename,
model=resolved_model,
diff --git a/skills/ppt-master/scripts/image_backends/backend_replicate.py b/skills/ppt-master/scripts/image_backends/backend_replicate.py
index 00704cb5..12241619 100644
--- a/skills/ppt-master/scripts/image_backends/backend_replicate.py
+++ b/skills/ppt-master/scripts/image_backends/backend_replicate.py
@@ -5,7 +5,7 @@ Replicate image generation backend.
Configuration keys:
REPLICATE_API_KEY / REPLICATE_API_TOKEN (required)
REPLICATE_BASE_URL (optional)
- REPLICATE_MODEL (optional)
+ REPLICATE_MODEL (optional; FLUX 1.1 Pro only)
"""
import sys
@@ -34,6 +34,7 @@ from image_backends.backend_common import (
download_image,
http_error,
is_rate_limit_error,
+ normalize_image_size,
poll_json,
require_api_key,
resolve_output_path,
@@ -44,6 +45,7 @@ from image_backends.backend_common import (
VALID_ASPECT_RATIOS = ["1:1", "16:9", "9:16", "3:4", "4:3", "3:2", "2:3", "4:5", "5:4", "21:9"]
DEFAULT_BASE_URL = "https://api.replicate.com/v1"
DEFAULT_MODEL = "black-forest-labs/flux-1.1-pro"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
def _split_model(model: str) -> tuple[str, str]:
@@ -56,6 +58,31 @@ def _split_model(model: str) -> tuple[str, str]:
return parts[0], parts[1]
+def _resolve_request_options(
+ aspect_ratio: str,
+ image_size: str,
+ model: str,
+) -> tuple[str, str]:
+ """Validate request options and return the Replicate model path."""
+ resolved_model = model.strip()
+ if resolved_model not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported Replicate model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ if aspect_ratio not in VALID_ASPECT_RATIOS:
+ raise ValueError(
+ f"Unsupported aspect ratio '{aspect_ratio}' for Replicate backend. "
+ f"Supported: {VALID_ASPECT_RATIOS}"
+ )
+ normalized_size = normalize_image_size(image_size)
+ if normalized_size != "1K":
+ raise ValueError(
+ "Replicate FLUX 1.1 Pro does not expose the unified image_size preset; "
+ f"only the default '1K' is supported, got '{image_size}'."
+ )
+ return _split_model(resolved_model)
+
+
def _extract_output_url(payload: dict) -> str | None:
"""Extract an output URL from a Replicate prediction payload."""
output = payload.get("output")
@@ -77,15 +104,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_BASE_URL) -> str:
"""Generate one image with the Replicate backend."""
- del image_size
-
- if aspect_ratio not in VALID_ASPECT_RATIOS:
- raise ValueError(
- f"Unsupported aspect ratio '{aspect_ratio}' for Replicate backend. "
- f"Supported: {VALID_ASPECT_RATIOS}"
- )
-
- owner, name = _split_model(model)
+ owner, name = _resolve_request_options(aspect_ratio, image_size, model)
url = f"{base_url.rstrip('/')}/models/{owner}/{name}/predictions"
headers = {
"Authorization": f"Bearer {api_key}",
@@ -148,13 +167,14 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Replicate backend."""
+ resolved_model = model or os.environ.get("REPLICATE_MODEL") or DEFAULT_MODEL
+ _resolve_request_options(aspect_ratio, image_size, resolved_model)
api_key = require_api_key(
"REPLICATE_API_KEY",
"REPLICATE_API_TOKEN",
message="No API key found. Set REPLICATE_API_KEY or REPLICATE_API_TOKEN in the current environment or a .env file.",
)
base_url = os.environ.get("REPLICATE_BASE_URL") or DEFAULT_BASE_URL
- resolved_model = model or os.environ.get("REPLICATE_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_siliconflow.py b/skills/ppt-master/scripts/image_backends/backend_siliconflow.py
index 6cf4f334..77fc56c7 100644
--- a/skills/ppt-master/scripts/image_backends/backend_siliconflow.py
+++ b/skills/ppt-master/scripts/image_backends/backend_siliconflow.py
@@ -5,7 +5,7 @@ SiliconFlow image generation backend.
Configuration keys:
SILICONFLOW_API_KEY (required)
SILICONFLOW_BASE_URL (optional)
- SILICONFLOW_MODEL (optional)
+ SILICONFLOW_MODEL (optional; Qwen/Qwen-Image only)
"""
import sys
@@ -43,55 +43,31 @@ from image_backends.backend_common import (
DEFAULT_ENDPOINT = "https://api.siliconflow.cn/v1/images/generations"
DEFAULT_MODEL = "Qwen/Qwen-Image"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
ASPECT_RATIO_SIZE_MAP = {
- "512px": {
- "1:1": "1024x1024",
- "2:3": "1056x1584",
- "3:2": "1584x1056",
- "3:4": "1140x1472",
- "4:3": "1472x1140",
- "4:5": "1140x1425",
- "5:4": "1425x1140",
- "9:16": "928x1664",
- "16:9": "1664x928",
- },
"1K": {
"1:1": "1328x1328",
"2:3": "1056x1584",
"3:2": "1584x1056",
"3:4": "1140x1472",
"4:3": "1472x1140",
- "4:5": "1140x1425",
- "5:4": "1425x1140",
"9:16": "928x1664",
"16:9": "1664x928",
},
- "2K": {
- "1:1": "2048x2048",
- "2:3": "1536x2048",
- "3:2": "2048x1536",
- "3:4": "1536x2048",
- "4:3": "2048x1536",
- "4:5": "1638x2048",
- "5:4": "2048x1638",
- "9:16": "1152x2048",
- "16:9": "2048x1152",
- },
- "4K": {
- "1:1": "2048x2048",
- "2:3": "1536x2048",
- "3:2": "2048x1536",
- "3:4": "1536x2048",
- "4:3": "2048x1536",
- "4:5": "1638x2048",
- "5:4": "2048x1638",
- "9:16": "1152x2048",
- "16:9": "2048x1152",
- },
}
+def _validate_model(model: str) -> str:
+ """Limit the backend to the Qwen-Image contract implemented below."""
+ resolved = model.strip()
+ if resolved not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported SiliconFlow model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ return resolved
+
+
def _resolve_url(base_url: str) -> str:
"""Resolve the SiliconFlow generation endpoint."""
base = base_url.rstrip("/")
@@ -103,9 +79,16 @@ def _resolve_url(base_url: str) -> str:
def _resolve_size(aspect_ratio: str, image_size: str) -> str:
"""Resolve the target resolution for a ratio and logical size preset."""
normalized = normalize_image_size(image_size)
- size = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)
+ sizes = ASPECT_RATIO_SIZE_MAP.get(normalized)
+ if sizes is None:
+ supported_sizes = ", ".join(ASPECT_RATIO_SIZE_MAP)
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for SiliconFlow backend. "
+ f"Qwen/Qwen-Image supports these logical sizes: {supported_sizes}."
+ )
+ size = sizes.get(aspect_ratio)
if not size:
- supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])
+ supported = sorted(sizes)
raise ValueError(
f"Unsupported aspect ratio '{aspect_ratio}' for SiliconFlow backend. "
f"Supported: {supported}"
@@ -118,6 +101,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the SiliconFlow backend."""
+ model = _validate_model(model)
size = _resolve_size(aspect_ratio, image_size)
url = _resolve_url(base_url)
headers = {
@@ -160,12 +144,15 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the SiliconFlow backend."""
+ resolved_model = model or os.environ.get("SILICONFLOW_MODEL") or DEFAULT_MODEL
+ _validate_model(resolved_model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_size(aspect_ratio, normalized_size)
api_key = require_api_key(
"SILICONFLOW_API_KEY",
message="No API key found. Set SILICONFLOW_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("SILICONFLOW_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("SILICONFLOW_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
@@ -174,7 +161,7 @@ def generate(prompt: str,
api_key=api_key,
prompt=prompt,
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=normalized_size,
output_dir=output_dir,
filename=filename,
model=resolved_model,
diff --git a/skills/ppt-master/scripts/image_backends/backend_stability.py b/skills/ppt-master/scripts/image_backends/backend_stability.py
index 8bb80bc9..fd0761b9 100644
--- a/skills/ppt-master/scripts/image_backends/backend_stability.py
+++ b/skills/ppt-master/scripts/image_backends/backend_stability.py
@@ -33,6 +33,7 @@ from image_backends.backend_common import (
MAX_RETRIES,
http_error,
is_rate_limit_error,
+ normalize_image_size,
report_resolution,
require_api_key,
resolve_output_path,
@@ -41,8 +42,8 @@ from image_backends.backend_common import (
VALID_ASPECT_RATIOS = [
- "1:1", "2:3", "3:2", "3:4", "4:3",
- "4:5", "5:4", "9:16", "16:9", "21:9",
+ "1:1", "2:3", "3:2", "4:5", "5:4",
+ "9:16", "16:9", "9:21", "21:9",
]
DEFAULT_BASE_URL = "https://api.stability.ai"
@@ -56,11 +57,24 @@ MODEL_ENDPOINTS = {
}
-def _resolve_endpoint(model: str, image_size: str, base_url: str) -> tuple[str, str]:
+def _validate_request_options(aspect_ratio: str, image_size: str) -> None:
+ """Validate unified request options before any retryable work."""
+ if aspect_ratio not in VALID_ASPECT_RATIOS:
+ raise ValueError(
+ f"Unsupported aspect ratio '{aspect_ratio}' for Stability backend. "
+ f"Supported: {VALID_ASPECT_RATIOS}"
+ )
+ normalized_size = normalize_image_size(image_size)
+ if normalized_size != "1K":
+ raise ValueError(
+ "Stability Core and Ultra generation only support the default '1K' preset; "
+ f"got '{image_size}'. Use a Stability upscale endpoint for larger output."
+ )
+
+
+def _resolve_endpoint(model: str | None, base_url: str) -> tuple[str, str]:
"""Resolve the Stability model alias and endpoint URL."""
resolved_model = model or DEFAULT_MODEL
- if not model and image_size.upper() in ("2K", "4K"):
- resolved_model = "stable-image-ultra"
normalized_model = resolved_model.lower()
endpoint = MODEL_ENDPOINTS.get(normalized_model)
@@ -75,15 +89,11 @@ def _resolve_endpoint(model: str, image_size: str, base_url: str) -> tuple[str,
def _generate_image(api_key: str, prompt: str,
aspect_ratio: str = "1:1", image_size: str = "1K",
output_dir: str = None, filename: str = None,
- model: str = DEFAULT_MODEL, base_url: str = DEFAULT_BASE_URL) -> str:
+ model: str | None = None, base_url: str = DEFAULT_BASE_URL) -> str:
"""Generate one image with the Stability backend."""
- if aspect_ratio not in VALID_ASPECT_RATIOS:
- raise ValueError(
- f"Unsupported aspect ratio '{aspect_ratio}' for Stability backend. "
- f"Supported: {VALID_ASPECT_RATIOS}"
- )
+ _validate_request_options(aspect_ratio, image_size)
- resolved_model, url = _resolve_endpoint(model, image_size, base_url)
+ resolved_model, url = _resolve_endpoint(model, base_url)
headers = {
"Authorization": f"Bearer {api_key}",
"Accept": "image/*",
@@ -103,7 +113,13 @@ def _generate_image(api_key: str, prompt: str,
print(" [..] Generating...", end="", flush=True)
start = time.time()
- response = requests.post(url, headers=headers, data=data, timeout=300)
+ response = requests.post(
+ url,
+ headers=headers,
+ data=data,
+ files={"none": ""},
+ timeout=300,
+ )
elapsed = time.time() - start
print(f"\n [DONE] Response received ({elapsed:.1f}s)")
@@ -123,12 +139,14 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Stability backend."""
+ base_url = os.environ.get("STABILITY_BASE_URL") or DEFAULT_BASE_URL
+ resolved_model = model or os.environ.get("STABILITY_MODEL")
+ _validate_request_options(aspect_ratio, image_size)
+ _resolve_endpoint(resolved_model, base_url)
api_key = require_api_key(
"STABILITY_API_KEY",
message="No API key found. Set STABILITY_API_KEY in the current environment or a .env file.",
)
- base_url = os.environ.get("STABILITY_BASE_URL") or DEFAULT_BASE_URL
- resolved_model = model or os.environ.get("STABILITY_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
diff --git a/skills/ppt-master/scripts/image_backends/backend_volcengine.py b/skills/ppt-master/scripts/image_backends/backend_volcengine.py
index 3a82966c..96a5bd99 100644
--- a/skills/ppt-master/scripts/image_backends/backend_volcengine.py
+++ b/skills/ppt-master/scripts/image_backends/backend_volcengine.py
@@ -3,9 +3,9 @@
Volcengine Seedream image generation backend.
Configuration keys:
- VOLCENGINE_API_KEY / ARK_API_KEY (required)
+ LAS_API_KEY / VOLCENGINE_API_KEY / ARK_API_KEY (required)
VOLCENGINE_BASE_URL (optional)
- VOLCENGINE_MODEL (optional)
+ VOLCENGINE_MODEL (optional; Seedream 4.5 only)
"""
import sys
@@ -43,73 +43,66 @@ from image_backends.backend_common import (
DEFAULT_ENDPOINT = "https://operator.las.cn-beijing.volces.com/api/v1/images/generations"
DEFAULT_MODEL = "doubao-seedream-4-5-251128"
+DEFAULT_IMAGE_SIZE = "2K"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
ASPECT_RATIO_SIZE_MAP = {
- "512px": {
- "1:1": "1024x1024",
- "2:3": "1024x1536",
- "3:2": "1536x1024",
- "3:4": "1024x1365",
- "4:3": "1365x1024",
- "4:5": "1024x1280",
- "5:4": "1280x1024",
- "9:16": "1024x1820",
- "16:9": "1820x1024",
- "21:9": "2048x878",
- },
- "1K": {
- "1:1": "1536x1536",
- "2:3": "1344x2016",
- "3:2": "2016x1344",
- "3:4": "1440x1920",
- "4:3": "1920x1440",
- "4:5": "1536x1920",
- "5:4": "1920x1536",
- "9:16": "1152x2048",
- "16:9": "2048x1152",
- "21:9": "2048x878",
- },
"2K": {
"1:1": "2048x2048",
- "2:3": "1536x2048",
- "3:2": "2048x1536",
- "3:4": "1536x2048",
- "4:3": "2048x1536",
- "4:5": "1638x2048",
- "5:4": "2048x1638",
- "9:16": "1152x2048",
- "16:9": "2048x1152",
- "21:9": "2048x878",
+ "2:3": "1664x2496",
+ "3:2": "2496x1664",
+ "3:4": "1728x2304",
+ "4:3": "2304x1728",
+ "9:16": "1600x2848",
+ "16:9": "2848x1600",
+ "21:9": "3136x1344",
},
"4K": {
- "1:1": "2048x2048",
- "2:3": "1536x2048",
- "3:2": "2048x1536",
- "3:4": "1536x2048",
- "4:3": "2048x1536",
- "4:5": "1638x2048",
- "5:4": "2048x1638",
- "9:16": "1152x2048",
- "16:9": "2048x1152",
- "21:9": "2048x878",
+ "1:1": "4096x4096",
+ "2:3": "3328x4992",
+ "3:2": "4992x3328",
+ "3:4": "3520x4704",
+ "4:3": "4704x3520",
+ "9:16": "3040x5504",
+ "16:9": "5504x3040",
+ "21:9": "6240x2656",
},
}
+def _validate_model(model: str) -> str:
+ """Limit the backend to the Seedream 4.5 contract implemented below."""
+ resolved = model.strip()
+ if resolved not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported Volcengine model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ return resolved
+
+
def _resolve_url(base_url: str) -> str:
"""Resolve the Volcengine generation endpoint."""
base = base_url.rstrip("/")
if base.endswith("/images/generations"):
return base
+ if base.endswith("/api/v1"):
+ return base + "/images/generations"
return base + "/api/v1/images/generations"
def _resolve_size(aspect_ratio: str, image_size: str) -> str:
"""Resolve the target resolution for a ratio and logical size preset."""
normalized = normalize_image_size(image_size)
- size = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)
+ sizes = ASPECT_RATIO_SIZE_MAP.get(normalized)
+ if sizes is None:
+ supported_sizes = ", ".join(ASPECT_RATIO_SIZE_MAP)
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for Volcengine backend. "
+ f"Seedream 4.5 supports these sizes: {supported_sizes}."
+ )
+ size = sizes.get(aspect_ratio)
if not size:
- supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])
+ supported = sorted(sizes)
raise ValueError(
f"Unsupported aspect ratio '{aspect_ratio}' for Volcengine backend. "
f"Supported: {supported}"
@@ -118,10 +111,11 @@ def _resolve_size(aspect_ratio: str, image_size: str) -> str:
def _generate_image(api_key: str, prompt: str,
- aspect_ratio: str = "1:1", image_size: str = "1K",
+ aspect_ratio: str = "1:1", image_size: str = DEFAULT_IMAGE_SIZE,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the Volcengine backend."""
+ model = _validate_model(model)
size = _resolve_size(aspect_ratio, image_size)
url = _resolve_url(base_url)
headers = {
@@ -162,17 +156,24 @@ def _generate_image(api_key: str, prompt: str,
def generate(prompt: str,
- aspect_ratio: str = "1:1", image_size: str = "1K",
+ aspect_ratio: str = "1:1", image_size: str = DEFAULT_IMAGE_SIZE,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Volcengine backend."""
+ resolved_model = model or os.environ.get("VOLCENGINE_MODEL") or DEFAULT_MODEL
+ _validate_model(resolved_model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_size(aspect_ratio, normalized_size)
api_key = require_api_key(
+ "LAS_API_KEY",
"VOLCENGINE_API_KEY",
"ARK_API_KEY",
- message="No API key found. Set VOLCENGINE_API_KEY or ARK_API_KEY in the current environment or a .env file.",
+ message=(
+ "No API key found. Set LAS_API_KEY, VOLCENGINE_API_KEY, or "
+ "ARK_API_KEY in the current environment or a .env file."
+ ),
)
base_url = os.environ.get("VOLCENGINE_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("VOLCENGINE_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
@@ -181,7 +182,7 @@ def generate(prompt: str,
api_key=api_key,
prompt=prompt,
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=normalized_size,
output_dir=output_dir,
filename=filename,
model=resolved_model,
diff --git a/skills/ppt-master/scripts/image_backends/backend_zhipu.py b/skills/ppt-master/scripts/image_backends/backend_zhipu.py
index 7b16671b..857a24d6 100644
--- a/skills/ppt-master/scripts/image_backends/backend_zhipu.py
+++ b/skills/ppt-master/scripts/image_backends/backend_zhipu.py
@@ -5,7 +5,7 @@ Zhipu GLM-Image generation backend.
Configuration keys:
ZHIPU_API_KEY / BIGMODEL_API_KEY (required)
ZHIPU_BASE_URL (optional)
- ZHIPU_MODEL (optional)
+ ZHIPU_MODEL (optional; glm-image only)
"""
import sys
@@ -43,59 +43,46 @@ from image_backends.backend_common import (
DEFAULT_ENDPOINT = "https://open.bigmodel.cn/api/paas/v4/images/generations"
DEFAULT_MODEL = "glm-image"
+SUPPORTED_MODELS = {DEFAULT_MODEL}
ASPECT_RATIO_SIZE_MAP = {
- "512px": {
- "1:1": "1024x1024",
- "2:3": "768x1152",
- "3:2": "1152x768",
- "3:4": "864x1152",
- "4:3": "1152x864",
- "4:5": "1024x1280",
- "5:4": "1280x1024",
- "9:16": "720x1440",
- "16:9": "1440x720",
- "21:9": "1536x640",
- },
"1K": {
"1:1": "1280x1280",
- "2:3": "960x1440",
- "3:2": "1440x960",
- "3:4": "1024x1365",
- "4:3": "1365x1024",
+ "2:3": "1056x1568",
+ "3:2": "1568x1056",
+ "3:4": "1088x1472",
+ "4:3": "1472x1088",
"4:5": "1024x1280",
"5:4": "1280x1024",
- "9:16": "768x1344",
- "16:9": "1344x768",
- "21:9": "1536x640",
+ "9:16": "960x1728",
+ "16:9": "1728x960",
+ "21:9": "1568x672",
},
"2K": {
- "1:1": "1440x1440",
- "2:3": "1152x1728",
- "3:2": "1728x1152",
- "3:4": "1152x1536",
- "4:3": "1536x1152",
- "4:5": "1280x1600",
- "5:4": "1600x1280",
- "9:16": "720x1440",
- "16:9": "1440x720",
- "21:9": "1792x768",
- },
- "4K": {
- "1:1": "1440x1440",
- "2:3": "1152x1728",
- "3:2": "1728x1152",
- "3:4": "1152x1536",
- "4:3": "1536x1152",
- "4:5": "1280x1600",
- "5:4": "1600x1280",
- "9:16": "720x1440",
- "16:9": "1440x720",
- "21:9": "1792x768",
+ "1:1": "2048x2048",
+ "2:3": "1344x2016",
+ "3:2": "2016x1344",
+ "3:4": "1536x2048",
+ "4:3": "2048x1536",
+ "4:5": "1536x1920",
+ "5:4": "1920x1536",
+ "9:16": "1152x2048",
+ "16:9": "2048x1152",
+ "21:9": "2016x864",
},
}
+def _validate_model(model: str) -> str:
+ """Limit the backend to the GLM-Image contract implemented below."""
+ resolved = model.strip()
+ if resolved not in SUPPORTED_MODELS:
+ raise ValueError(
+ f"Unsupported Zhipu model '{model}'. Supported: {sorted(SUPPORTED_MODELS)}"
+ )
+ return resolved
+
+
def _resolve_url(base_url: str) -> str:
"""Resolve the Zhipu generation endpoint."""
base = base_url.rstrip("/")
@@ -107,9 +94,16 @@ def _resolve_url(base_url: str) -> str:
def _resolve_size(aspect_ratio: str, image_size: str) -> str:
"""Resolve the target resolution for a ratio and logical size preset."""
normalized = normalize_image_size(image_size)
- size = (ASPECT_RATIO_SIZE_MAP.get(normalized) or {}).get(aspect_ratio)
+ sizes = ASPECT_RATIO_SIZE_MAP.get(normalized)
+ if sizes is None:
+ supported_sizes = ", ".join(ASPECT_RATIO_SIZE_MAP)
+ raise ValueError(
+ f"Unsupported image size '{image_size}' for Zhipu backend. "
+ f"GLM-Image supports these logical sizes: {supported_sizes}."
+ )
+ size = sizes.get(aspect_ratio)
if not size:
- supported = sorted(ASPECT_RATIO_SIZE_MAP["1K"])
+ supported = sorted(sizes)
raise ValueError(
f"Unsupported aspect ratio '{aspect_ratio}' for Zhipu backend. "
f"Supported: {supported}"
@@ -122,6 +116,7 @@ def _generate_image(api_key: str, prompt: str,
output_dir: str = None, filename: str = None,
model: str = DEFAULT_MODEL, base_url: str = DEFAULT_ENDPOINT) -> str:
"""Generate one image with the Zhipu backend."""
+ model = _validate_model(model)
size = _resolve_size(aspect_ratio, image_size)
url = _resolve_url(base_url)
headers = {
@@ -165,13 +160,16 @@ def generate(prompt: str,
output_dir: str = None, filename: str = None,
model: str = None, max_retries: int = MAX_RETRIES) -> str:
"""Generate an image with retries using the Zhipu backend."""
+ resolved_model = model or os.environ.get("ZHIPU_MODEL") or DEFAULT_MODEL
+ _validate_model(resolved_model)
+ normalized_size = normalize_image_size(image_size)
+ _resolve_size(aspect_ratio, normalized_size)
api_key = require_api_key(
"ZHIPU_API_KEY",
"BIGMODEL_API_KEY",
message="No API key found. Set ZHIPU_API_KEY or BIGMODEL_API_KEY in the current environment or a .env file.",
)
base_url = os.environ.get("ZHIPU_BASE_URL") or DEFAULT_ENDPOINT
- resolved_model = model or os.environ.get("ZHIPU_MODEL") or DEFAULT_MODEL
last_error = None
for attempt in range(max_retries + 1):
@@ -180,7 +178,7 @@ def generate(prompt: str,
api_key=api_key,
prompt=prompt,
aspect_ratio=aspect_ratio,
- image_size=image_size,
+ image_size=normalized_size,
output_dir=output_dir,
filename=filename,
model=resolved_model,
diff --git a/skills/ppt-master/scripts/image_gen.py b/skills/ppt-master/scripts/image_gen.py
index ce01a34f..38a94302 100644
--- a/skills/ppt-master/scripts/image_gen.py
+++ b/skills/ppt-master/scripts/image_gen.py
@@ -74,6 +74,7 @@ IMAGE_ENV_PREFIXES = (
"ZHIPU_",
"BIGMODEL_",
"VOLCENGINE_",
+ "LAS_",
"ARK_",
"MODELSCOPE_",
"SILICONFLOW_",
@@ -90,9 +91,10 @@ DEPRECATED_IMAGE_KEYS = {
# All aspect ratios accepted by the unified CLI
# (each backend validates its own subset internally)
ALL_ASPECT_RATIOS = [
- "1:1", "1:4", "1:8",
- "2:3", "3:2", "3:4", "4:1", "4:3",
- "4:5", "5:4", "8:1", "9:16", "16:9", "21:9"
+ "1:1", "1:2", "1:3", "1:4", "1:8",
+ "2:1", "2:3", "3:1", "3:2", "3:4", "4:1", "4:3",
+ "4:5", "5:4", "8:1", "9:16", "9:21", "10:16",
+ "16:9", "16:10", "21:9",
]
ALL_IMAGE_SIZES = ["512px", "1K", "2K", "4K"]
@@ -102,7 +104,8 @@ BACKEND_REGISTRY = {
"module": "backend_gemini",
"tier": "core",
"label": "Google Gemini",
- "default_model": "gemini-3.1-flash-image-preview",
+ "default_model": "gemini-3.1-flash-image",
+ "default_image_size": "1K",
"key_hint": "GEMINI_API_KEY",
"aliases": ["google"],
},
@@ -111,6 +114,7 @@ BACKEND_REGISTRY = {
"tier": "core",
"label": "OpenAI / OpenAI-compatible",
"default_model": "gpt-image-2",
+ "default_image_size": "1K",
"key_hint": "OPENAI_API_KEY",
"aliases": ["openai-compatible", "openai_compatible"],
},
@@ -119,6 +123,7 @@ BACKEND_REGISTRY = {
"tier": "experimental",
"label": "MiniMax Image",
"default_model": "image-01",
+ "default_image_size": "1K",
"key_hint": "MINIMAX_API_KEY",
"aliases": ["minimaxi"],
},
@@ -127,6 +132,7 @@ BACKEND_REGISTRY = {
"tier": "core",
"label": "Alibaba Qwen Image",
"default_model": "qwen-image-2.0-pro",
+ "default_image_size": "1K",
"key_hint": "QWEN_API_KEY / DASHSCOPE_API_KEY",
"aliases": ["alibaba", "dashscope"],
},
@@ -135,6 +141,7 @@ BACKEND_REGISTRY = {
"tier": "core",
"label": "Zhipu GLM-Image",
"default_model": "glm-image",
+ "default_image_size": "1K",
"key_hint": "ZHIPU_API_KEY / BIGMODEL_API_KEY",
"aliases": ["bigmodel", "glm", "glm-image"],
},
@@ -143,14 +150,17 @@ BACKEND_REGISTRY = {
"tier": "core",
"label": "Volcengine Seedream",
"default_model": "doubao-seedream-4-5-251128",
- "key_hint": "VOLCENGINE_API_KEY / ARK_API_KEY",
+ "default_image_size": "2K",
+ "key_hint": "LAS_API_KEY / VOLCENGINE_API_KEY / ARK_API_KEY",
"aliases": ["ark", "doubao", "seedream"],
},
"modelscope": {
"module": "backend_modelscope",
"tier": "experimental",
"label": "ModelScope",
- "default_model": "Tongyi-MAI/Z-Image-Turbo",
+ "default_model": None,
+ "model_hint": "MODELSCOPE_MODEL",
+ "default_image_size": "1K",
"key_hint": "MODELSCOPE_API_KEY",
"aliases": ["modelscope", "model-scope"]
},
@@ -159,6 +169,7 @@ BACKEND_REGISTRY = {
"tier": "extended",
"label": "Stability AI",
"default_model": "stable-image-core",
+ "default_image_size": "1K",
"key_hint": "STABILITY_API_KEY",
"aliases": ["stabilityai", "stability-ai"],
},
@@ -167,6 +178,7 @@ BACKEND_REGISTRY = {
"tier": "extended",
"label": "Black Forest Labs FLUX",
"default_model": "flux-pro-1.1-ultra",
+ "default_image_size": "1K",
"key_hint": "BFL_API_KEY",
"aliases": ["flux", "black-forest-labs", "black_forest_labs"],
},
@@ -175,6 +187,7 @@ BACKEND_REGISTRY = {
"tier": "extended",
"label": "Ideogram",
"default_model": "ideogram-v3",
+ "default_image_size": "1K",
"key_hint": "IDEOGRAM_API_KEY",
},
"siliconflow": {
@@ -182,6 +195,7 @@ BACKEND_REGISTRY = {
"tier": "experimental",
"label": "SiliconFlow",
"default_model": "Qwen/Qwen-Image",
+ "default_image_size": "1K",
"key_hint": "SILICONFLOW_API_KEY",
"aliases": ["silicon"],
},
@@ -189,7 +203,8 @@ BACKEND_REGISTRY = {
"module": "backend_fal",
"tier": "experimental",
"label": "fal.ai",
- "default_model": "fal-ai/imagen3/fast",
+ "default_model": "fal-ai/nano-banana-2",
+ "default_image_size": "1K",
"key_hint": "FAL_KEY / FAL_API_KEY",
"aliases": ["fal-ai"],
},
@@ -198,13 +213,15 @@ BACKEND_REGISTRY = {
"tier": "experimental",
"label": "Replicate",
"default_model": "black-forest-labs/flux-1.1-pro",
+ "default_image_size": "1K",
"key_hint": "REPLICATE_API_TOKEN / REPLICATE_API_KEY",
},
"openrouter": {
"module": "backend_openrouter",
"tier": "experimental",
"label": "OpenRouter",
- "default_model": "google/gemini-3.1-flash-image-preview",
+ "default_model": "google/gemini-3.1-flash-image",
+ "default_image_size": "1K",
"key_hint": "OPENROUTER_API_KEY",
},
}
@@ -299,8 +316,14 @@ def _print_backend_list() -> None:
):
if info["tier"] != tier:
continue
+ if info["default_model"]:
+ model_label = f"default={info['default_model']}"
+ else:
+ model_label = f"model=required via {info['model_hint']}"
print(
- f" {name:<12} {info['label']} | default={info['default_model']} | keys={info['key_hint']}"
+ f" {name:<12} {info['label']} | "
+ f"{model_label} | "
+ f"size={info['default_image_size']} | keys={info['key_hint']}"
)
print()
print("Recommendation: prefer CORE backends for everyday PPT generation.")
@@ -1122,8 +1145,11 @@ def main() -> None:
help=f"Aspect ratio. Default: 1:1."
)
parser.add_argument(
- "--image_size", default="1K",
- help=f"Image size. Choices: {ALL_IMAGE_SIZES}. Default: 1K. (case-insensitive)"
+ "--image_size", default=None,
+ help=(
+ f"Image size. Choices: {ALL_IMAGE_SIZES}. Default depends on the "
+ "backend and is shown by --list-backends. (case-insensitive)"
+ ),
)
parser.add_argument(
"--output", "-o", default=None,
@@ -1261,6 +1287,10 @@ def main() -> None:
os.environ["IMAGE_BACKEND"] = args.backend
backend, backend_name = _resolve_backend()
+ image_size = (
+ args.image_size
+ or BACKEND_REGISTRY[backend_name]["default_image_size"]
+ )
print(f"Using backend: {backend_name}\n")
if args.manifest:
@@ -1269,7 +1299,7 @@ def main() -> None:
_, failed, _ = _run_manifest(
manifest, args.manifest, backend,
initial_concurrency=concurrency,
- image_size=args.image_size,
+ image_size=image_size,
output_dir=str(manifest_output_dir),
model=args.model,
)
@@ -1288,7 +1318,7 @@ def main() -> None:
gen_kwargs = {
"prompt": prompt,
"aspect_ratio": args.aspect_ratio,
- "image_size": args.image_size,
+ "image_size": image_size,
"output_dir": args.output,
"filename": args.filename,
"model": args.model,