imagegen

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package imagegen implements an image-generation agent that drives OpenRouter image-output models (e.g. google/gemini-3.1-flash-image-preview).

Unlike text agents, imagegen does not implement the generic agent.Agent interface: its I/O shape (base64-decoded PNGs) is too specific and wrapping it in a generic Response would lose type safety.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent wraps an OpenRouter client and emits image-generation requests with modalities=["image","text"] set.

func New

func New(client openrouter.Client, cfg *config.ImageGeneratorConfig, logger *slog.Logger) *Agent

New constructs an image-generation Agent.

func (*Agent) Generate

func (a *Agent) Generate(ctx context.Context, req Request) (*Response, error)

Generate runs a single image-generation call. It never returns partial results: if the model produced zero images it returns an error the caller can surface to the user.

type DecodedImage

type DecodedImage struct {
	MimeType string // e.g. "image/png"
	Data     []byte // raw decoded bytes
}

DecodedImage is a single output image with its MIME type.

type Request

type Request struct {
	UserID int64

	// Prompt is the text description of the image to generate, in any language.
	Prompt string

	// InputImages are reference images for editing/combining. Pass the
	// user's attached photos or artifacts loaded from storage. May be empty
	// for pure text-to-image generation.
	InputImages []openrouter.FilePart

	// AspectRatio is one of the values accepted by the target model, e.g.
	// "1:1", "16:9", "21:9". Empty means model default (typically 1:1).
	AspectRatio string

	// ImageSize is one of "0.5K", "1K", "2K", "4K". Empty means model default.
	ImageSize string
}

Request parameters for a single image generation call.

type Response

type Response struct {
	Images      []DecodedImage
	TextContent string // Optional text the model emitted alongside images

	PromptTokens     int
	CompletionTokens int
	Cost             *float64
	Duration         time.Duration
}

Response contains generated images and accounting metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL