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
Functions
@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.
Return the params formatted for a ModelsLab API request.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Build a new ModelsLabImage configuration.
Build a new ModelsLabImage configuration and return it or raise on error.