Jido.AI.Actions.OpenaiEx.ImageGeneration (Jido AI v0.5.2)

View Source

Action module for generating images using OpenAI Ex.

This module supports image generation with both OpenAI and OpenRouter providers. It uses the DALL-E models to create images from text prompts with various customization options.

Features

  • Support for both OpenAI and OpenRouter providers
  • Customizable image generation parameters (size, quality, style)
  • Multiple image generation in a single request
  • Support for different response formats (URL or base64)
  • Consistent error handling and validation

Usage

# Generate a single image
{:ok, result} = Jido.AI.Actions.OpenaiEx.ImageGeneration.run(
  %{
    model: %Jido.AI.Model{provider: :openai, model: "dall-e-3", api_key: "key"},
    prompt: "A beautiful sunset over the ocean"
  },
  %{}
)

# Generate multiple images with custom parameters
{:ok, result} = Jido.AI.Actions.OpenaiEx.ImageGeneration.run(
  %{
    model: %Jido.AI.Model{provider: :openai, model: "dall-e-3", api_key: "key"},
    prompt: "A beautiful sunset over the ocean",
    n: 2,
    size: "1024x1792",
    quality: "hd",
    style: "natural"
  },
  %{}
)

Summary

Functions

category()

description()

name()

on_after_run(result)

Callback implementation for Jido.Action.on_after_run/1.

on_after_validate_params(params)

Callback implementation for Jido.Action.on_after_validate_params/1.

on_before_validate_params(params)

Callback implementation for Jido.Action.on_before_validate_params/1.

on_error(failed_params, error, context, opts)

Callback implementation for Jido.Action.on_error/4.

run(params, context)

@spec run(map(), map()) :: {:ok, map()} | {:error, any()}
@spec run(map(), map()) :: {:ok, %{images: [String.t()]}} | {:error, String.t()}

Generates images from a text prompt using OpenAI Ex.

Parameters

  • params: Map containing:
    • model: Either a %Jido.AI.Model{} struct or a tuple of {provider, opts}
    • prompt: Text description of the desired image
    • n: Optional number of images to generate (1-10)
    • size: Optional size of the generated images
    • quality: Optional quality level ("standard" or "hd")
    • style: Optional style ("vivid" or "natural")
    • response_format: Optional format ("url" or "b64_json")
  • context: The action context containing state and other information

Returns

  • } on success where images is a list of URLs or base64 strings
  • on failure

schema()

tags()

to_json()

to_tool()

validate_params(params)

@spec validate_params(map()) :: {:ok, map()} | {:error, String.t()}

Validates the input parameters for the Action.

Examples

iex> defmodule ExampleAction do
...>   use Jido.Action,
...>     name: "example_action",
...>     schema: [
...>       input: [type: :string, required: true]
...>     ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}

iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}

vsn()