Skip to content

Commit 3718b94

Browse files
authored
feat(blocks): Add Ideogram V3 model (#10752)
Adds support for Ideogram V3 model while maintaining backward compatibility with existing models (V1, V1_TURBO, V2, V2_TURBO). Updates default model to V3 and implements smart API routing to handle Ideogram's new V3 endpoint requirements. Changes Made - Added V3 model support: Added V_3 to IdeogramModelName enum and set as default - Dual API endpoint handling: - V3 models route to new /v1/ideogram-v3/generate endpoint with updated payload format - Legacy models (V1, V2, Turbo variants) continue using /generate endpoint - Model-specific feature filtering: - V1 models: Basic parameters only (no style_type or color_palette support) - V2/V2_TURBO: Full legacy feature support including style_type and color_palette - V3: New endpoint with aspect ratio mapping and updated parameter structure - Aspect ratio compatibility: Added mapping between internal enum values and V3's expected format (ASPECT_1_1 → 1x1) - Updated pricing: V3 model costs 18 credits (vs 16 for other models) - Updated default usage: Store image generation now uses V3 by default Technical Details Ideogram updated their API with a separate V3 endpoint that has different requirements: - Different URL path (/v1/ideogram-v3/generate) - Different aspect ratio format (e.g., 1x1 instead of ASPECT_1_1) - Model-specific feature support (V1 models don't support style_type, etc.) The implementation intelligently routes requests to the appropriate endpoint based on the selected model while maintaining a single unified interface. I tested all the models and they are working here <img width="1804" height="887" alt="image" src="https://github.com/user-attachments/assets/9f2e44ca-50a4-487f-987c-3230dd72fb5e" /> ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: <!-- Put your test plan here: --> - [x] Test the Ideogram model block and watch as they all work!
1 parent 44d7393 commit 3718b94

File tree

3 files changed

+134
-12
lines changed

3 files changed

+134
-12
lines changed

autogpt_platform/backend/backend/blocks/ideogram.py

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131

3232
class IdeogramModelName(str, Enum):
33+
V3 = "V_3"
3334
V2 = "V_2"
3435
V1 = "V_1"
3536
V1_TURBO = "V_1_TURBO"
@@ -95,8 +96,8 @@ class Input(BlockSchema):
9596
title="Prompt",
9697
)
9798
ideogram_model_name: IdeogramModelName = SchemaField(
98-
description="The name of the Image Generation Model, e.g., V_2",
99-
default=IdeogramModelName.V2,
99+
description="The name of the Image Generation Model, e.g., V_3",
100+
default=IdeogramModelName.V3,
100101
title="Image Generation Model",
101102
advanced=False,
102103
)
@@ -236,6 +237,111 @@ async def run_model(
236237
negative_prompt: Optional[str],
237238
color_palette_name: str,
238239
custom_colors: Optional[list[str]],
240+
):
241+
# Use V3 endpoint for V3 model, legacy endpoint for others
242+
if model_name == "V_3":
243+
return await self._run_model_v3(
244+
api_key,
245+
prompt,
246+
seed,
247+
aspect_ratio,
248+
magic_prompt_option,
249+
style_type,
250+
negative_prompt,
251+
color_palette_name,
252+
custom_colors,
253+
)
254+
else:
255+
return await self._run_model_legacy(
256+
api_key,
257+
model_name,
258+
prompt,
259+
seed,
260+
aspect_ratio,
261+
magic_prompt_option,
262+
style_type,
263+
negative_prompt,
264+
color_palette_name,
265+
custom_colors,
266+
)
267+
268+
async def _run_model_v3(
269+
self,
270+
api_key: SecretStr,
271+
prompt: str,
272+
seed: Optional[int],
273+
aspect_ratio: str,
274+
magic_prompt_option: str,
275+
style_type: str,
276+
negative_prompt: Optional[str],
277+
color_palette_name: str,
278+
custom_colors: Optional[list[str]],
279+
):
280+
url = "https://api.ideogram.ai/v1/ideogram-v3/generate"
281+
headers = {
282+
"Api-Key": api_key.get_secret_value(),
283+
"Content-Type": "application/json",
284+
}
285+
286+
# Map legacy aspect ratio values to V3 format
287+
aspect_ratio_map = {
288+
"ASPECT_10_16": "10x16",
289+
"ASPECT_16_10": "16x10",
290+
"ASPECT_9_16": "9x16",
291+
"ASPECT_16_9": "16x9",
292+
"ASPECT_3_2": "3x2",
293+
"ASPECT_2_3": "2x3",
294+
"ASPECT_4_3": "4x3",
295+
"ASPECT_3_4": "3x4",
296+
"ASPECT_1_1": "1x1",
297+
"ASPECT_1_3": "1x3",
298+
"ASPECT_3_1": "3x1",
299+
# Additional V3 supported ratios
300+
"ASPECT_1_2": "1x2",
301+
"ASPECT_2_1": "2x1",
302+
"ASPECT_4_5": "4x5",
303+
"ASPECT_5_4": "5x4",
304+
}
305+
306+
v3_aspect_ratio = aspect_ratio_map.get(
307+
aspect_ratio, "1x1"
308+
) # Default to 1x1 if not found
309+
310+
# Use JSON for V3 endpoint (simpler than multipart/form-data)
311+
data: Dict[str, Any] = {
312+
"prompt": prompt,
313+
"aspect_ratio": v3_aspect_ratio,
314+
"magic_prompt": magic_prompt_option,
315+
"style_type": style_type,
316+
}
317+
318+
if seed is not None:
319+
data["seed"] = seed
320+
321+
if negative_prompt:
322+
data["negative_prompt"] = negative_prompt
323+
324+
# Note: V3 endpoint may have different color palette support
325+
# For now, we'll omit color palettes for V3 to avoid errors
326+
327+
try:
328+
response = await Requests().post(url, headers=headers, json=data)
329+
return response.json()["data"][0]["url"]
330+
except RequestException as e:
331+
raise Exception(f"Failed to fetch image with V3 endpoint: {str(e)}")
332+
333+
async def _run_model_legacy(
334+
self,
335+
api_key: SecretStr,
336+
model_name: str,
337+
prompt: str,
338+
seed: Optional[int],
339+
aspect_ratio: str,
340+
magic_prompt_option: str,
341+
style_type: str,
342+
negative_prompt: Optional[str],
343+
color_palette_name: str,
344+
custom_colors: Optional[list[str]],
239345
):
240346
url = "https://api.ideogram.ai/generate"
241347
headers = {
@@ -249,28 +355,33 @@ async def run_model(
249355
"model": model_name,
250356
"aspect_ratio": aspect_ratio,
251357
"magic_prompt_option": magic_prompt_option,
252-
"style_type": style_type,
253358
}
254359
}
255360

361+
# Only add style_type for V2, V2_TURBO, and V3 models (V1 models don't support it)
362+
if model_name in ["V_2", "V_2_TURBO", "V_3"]:
363+
data["image_request"]["style_type"] = style_type
364+
256365
if seed is not None:
257366
data["image_request"]["seed"] = seed
258367

259368
if negative_prompt:
260369
data["image_request"]["negative_prompt"] = negative_prompt
261370

262-
if color_palette_name != "NONE":
263-
data["color_palette"] = {"name": color_palette_name}
264-
elif custom_colors:
265-
data["color_palette"] = {
266-
"members": [{"color_hex": color} for color in custom_colors]
267-
}
371+
# Only add color palette for V2 and V2_TURBO models (V1 models don't support it)
372+
if model_name in ["V_2", "V_2_TURBO"]:
373+
if color_palette_name != "NONE":
374+
data["color_palette"] = {"name": color_palette_name}
375+
elif custom_colors:
376+
data["color_palette"] = {
377+
"members": [{"color_hex": color} for color in custom_colors]
378+
}
268379

269380
try:
270381
response = await Requests().post(url, headers=headers, json=data)
271382
return response.json()["data"][0]["url"]
272383
except RequestException as e:
273-
raise Exception(f"Failed to fetch image: {str(e)}")
384+
raise Exception(f"Failed to fetch image with legacy endpoint: {str(e)}")
274385

275386
async def upscale_image(self, api_key: SecretStr, image_url: str):
276387
url = "https://api.ideogram.ai/upscale"

autogpt_platform/backend/backend/data/block_cost_config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,18 @@
307307
"type": ideogram_credentials.type,
308308
}
309309
},
310-
)
310+
),
311+
BlockCost(
312+
cost_amount=18,
313+
cost_filter={
314+
"ideogram_model_name": "V_3",
315+
"credentials": {
316+
"id": ideogram_credentials.id,
317+
"provider": ideogram_credentials.provider,
318+
"type": ideogram_credentials.type,
319+
},
320+
},
321+
),
311322
],
312323
AIShortformVideoCreatorBlock: [
313324
BlockCost(

autogpt_platform/backend/backend/server/v2/store/image_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def generate_agent_image_v2(graph: BaseGraph | AgentGraph) -> io.BytesIO:
8282
type=ideogram_credentials.type,
8383
),
8484
prompt=prompt,
85-
ideogram_model_name=IdeogramModelName.V2,
85+
ideogram_model_name=IdeogramModelName.V3,
8686
aspect_ratio=AspectRatio.ASPECT_16_9,
8787
magic_prompt_option=MagicPromptOption.OFF,
8888
style_type=StyleType.AUTO,

0 commit comments

Comments
 (0)