LangChain.Images.ModelsLabImage (LangChain v0.6.2)

Copy Markdown View Source

Represents the ModelsLab Images API for text-to-image generation using Flux, SDXL, Stable Diffusion, and 10,000+ community fine-tuned models.

Configuration

Set your API key in your application config:

config :langchain, :modelslab_key, "your-api-key"

Or pass it directly when creating the struct:

{:ok, ml_image} = ModelsLabImage.new(%{
  api_key: "your-api-key",
  prompt: "A cozy cabin in the woods at dusk"
})

Usage

{:ok, ml_image} = LangChain.Images.ModelsLabImage.new(%{
  prompt: "A sunset over mountains in watercolor style",
  model: "flux",
  width: 1024,
  height: 1024
})

{:ok, images} = LangChain.Images.ModelsLabImage.call(ml_image)
LangChain.Images.save_images({:ok, images}, "/tmp", "my_image_")

Available models

  • "flux" — High-quality photorealistic Flux model (default)
  • "flux-dev" — Flux development variant
  • "sdxl" — Stable Diffusion XL
  • "realistic-vision-v6" — Photorealistic portraits
  • "dreamshaper-8" — Artistic and creative styles
  • "anything-v5" — Anime and illustration style
  • Any community model ID from modelslab.com/models

API docs

Summary

Functions

Call the ModelsLab API and return generated images.

Return the params formatted for a ModelsLab API request.

Build a new ModelsLabImage configuration.

Build a new ModelsLabImage configuration and return it or raise on error.

Types

t()

@type t() :: %LangChain.Images.ModelsLabImage{
  api_key: term(),
  endpoint: term(),
  guidance_scale: term(),
  height: term(),
  model: term(),
  negative_prompt: term(),
  num_inference_steps: term(),
  prompt: term(),
  receive_timeout: term(),
  samples: term(),
  seed: term(),
  width: term()
}

Functions

call(ml_image)

@spec call(t()) :: {:ok, [LangChain.Images.GeneratedImage.t()]} | {:error, String.t()}

Call the ModelsLab API and return generated images.

Returns {:ok, [GeneratedImage.t()]} on success or {:error, reason} on failure.

for_api(ml_image)

@spec for_api(t()) :: map()

Return the params formatted for a ModelsLab API request.

new(attrs)

@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Build a new ModelsLabImage configuration.

new!(attrs)

@spec new!(attrs :: map()) :: t() | no_return()

Build a new ModelsLabImage configuration and return it or raise on error.