generation

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultVideoAspect     = "16:9"
	DefaultVideoResolution = "720p"
)
View Source
const DefaultAspect = "landscape"
View Source
const Generated = "cache/generated"

Folder of the profile what the services make is kept in, under the caches a sandbox is handed

View Source
const (
	// Address of OpenAI's API, where an OpenAI client goes when given none
	OpenAIBase = "https://api.openai.com/v1"
)
View Source
const Retry = 30 * time.Second

How long a catalog read that failed is kept before the service is asked again

View Source
const VideoTool = "video_generate"

Tool that makes videos, whose view the app shows every tool that hands back the envelope of a video with

Variables

View Source
var (
	VideoAspects     = []string{"16:9", "9:16", "1:1", "4:3", "3:4", "3:2", "2:3", "21:9"}
	VideoResolutions = []string{"480p", "540p", "720p", "768p", "1080p"}
)

Aspect ratios and resolutions video_generate takes when the service names none of its own, and its defaults

View Source
var Agent = provider.UserAgent("Icebath-Agent")

Name the services are told the calls come from

View Source
var Aspects = []string{"landscape", "square", "portrait"}

Shapes of picture image_generate takes, landscape when the call names another

View Source
var Controls = []string{"creativity", "thinking", "resolution", "intensity", "complexity", "movement"}

Creative controls a picture model may take, in the order image_generate lists them

View Source
var ErrUnsafe = errors.New("URL failed the SSRF safety check")

Refusal of a URL whose host is private or internal

Functions

func Aspect

func Aspect(text string) string

Shape of picture the text names, lower cased, landscape for anything else

func Base64

func Base64(text string) ([]byte, error)

Bytes of base64 in either alphabet, padded or not, whitespace ignored

func Chosen

func Chosen(cfg *config.Config, kind Kind) string

Service chosen for the kind, lower cased, empty when none is

func DataURL

func DataURL(mime string, data []byte) string

Data URL of the bytes

func Dir

func Dir(cfg *config.Config, kind Kind) (string, error)

Folder the profile keeps what was made of the kind in, made when missing

func Get

func Get(ctx context.Context, env httpx.Env, address string, headers map[string]string, timeout time.Duration) (map[string]any, error)

Reads a JSON object from a GET through the proxy and authorities of the environment, the profile's, an error naming the status and the head of the body when it failed

func Idle

func Idle(r io.Reader, limit time.Duration, cancel context.CancelFunc) ([]byte, error)

Body of a reply with every wait for more bounded by the limit, the request cancelled when one runs out

func Inline

func Inline(source string) ([]byte, string, error)

Bytes and declared type of a base64 data URL

func List

func List(value any, key string) []any

List under the key of an object, nil when there is none

func Message

func Message(_ int, body []byte) string

Message of a failed JSON reply: its error's message, else the first 300 characters of the body

func Object

func Object(value any) map[string]any

Object of a JSON value, nil for anything else

func On

func On(cfg *config.Config, kind Kind) bool

Whether the agent makes things of the kind at all: images always, videos only while Videos is on

func Remote

func Remote(source string) bool

Whether the source is a URL or a data URL rather than a path

func SetVideos

func SetVideos(cfg *config.Config, on bool) error

Turns the making of videos on or off, the one control of whether the agent makes them

func Shared

func Shared(name string) bool

Whether image_generate gives every service an argument of the name, so no service's own argument may take it

func Size

func Size(aspect string) string

Size the OpenAI images API and those that copy it take for the shape, square for an unknown one

func Sniff

func Sniff(data []byte) string

Type of an image from its first bytes, empty when it is none of png, jpeg, gif, webp, bmp, tiff, avif, heic or svg

func Status

func Status(code int, address string) error

Failed status of a reply, in the words of the requests library the model knows

func Text

func Text(value any, key string) string

Trimmed text under the key of an object, empty when it is no text

func TypeOf

func TypeOf(name string) string

Type a file's name gives, empty when it gives none

func Usage

func Usage(report any) (provider.Usage, bool)

Tokens a usage report of an images or chat API gives, the input counted without its cached part; false without any

func Whole

func Whole(value any) *int

Whole number of an argument: a number cut to its whole part, or a text of digits; nil for anything else, a true or false included

Types

type Call

type Call struct {
	Provider, Model, Prompt, Aspect string
}

Fields every result of one call carries

func (Call) Fail

func (c Call) Fail(text, kind string) Result

Failure of the call

func (Call) Made

func (c Call) Made(media, modality string, extra map[string]any) Result

What the call made, modality text when empty

type Catalogs

type Catalogs[T any] struct {
	Fresh, Retry time.Duration
	// contains filtered or unexported fields
}

Catalogs a service reads over the network, each kept by its key: a read that worked for Fresh, one that failed for Retry, so a service that is down is not asked again on every call. One read of a key runs at a time, and every caller asking for it meanwhile takes its answer; a read that failed as its caller's context ended is kept by nobody. Catalogs whose time is up are dropped as each read ends

func (*Catalogs[T]) Get

func (c *Catalogs[T]) Get(ctx context.Context, key string, read func(ctx context.Context) (T, bool)) T

Catalog of the key: the one kept while its time is not up, else the one read answers, the read reporting whether it worked. A caller that finds another reading the key waits for that read; one whose context ends first answers what read answers under that context, keeping nothing

type Failure

type Failure struct {
	// http, timeout, connection or invalid_json
	Kind  string
	Error string
	// Kind of failure the model reads, such as api_error
	Type string
	// Status and what the service said, for an http failure
	Status  int
	Message string
}

Why a JSON request failed, the error the model reads ready in Error

func Post

func Post(ctx context.Context, env httpx.Env, address string, headers map[string]string, payload any, connect, read time.Duration, label string,
	message func(status int, body []byte) string) (any, *Failure)

Posts JSON through the proxy and authorities of the environment, the profile's, and reads the JSON reply, or why it failed: a connect limit and a limit on each wait for the service; message words what a failed reply says, Message when nil

func (*Failure) Said

func (f *Failure) Said(used, shown string) *Failure

The failure with the start of an address a setting writes with a reference, as shown, said as written in the place of the start it comes to, used, so no failure shows the value of a variable a setting names; the failure itself when the two are the same

type Fetch

type Fetch struct {
	Prefix  string
	Timeout time.Duration
	Max     int64
	// Headers sent on the hops to the service's own endpoint, nowhere else
	Headers map[string]string
	// Refuses a reply whose content type is not one of the kind
	Strict bool
	// Address of the API the service was called on: a download from that very endpoint skips the private address checks, only cloud
	// metadata staying refused, and is the only place the headers go
	Origin string
}

How one download goes, zero values taking the defaults of the kind

type Generation

type Generation struct {
	Registry
}

Image and video services of the plugins, and the cache what they make is kept in

func New

func New(cfg *config.Config) *Generation

The choices of service the settings offer list those of the profile whose settings are read

func (*Generation) Register

func (g *Generation) Register(registrant Registrant)

Adds a registrant; a registry nested in the host reaches it through Host

type ImageRequest

type ImageRequest struct {
	Prompt string
	// landscape, square or portrait
	Aspect string
	// Picture to edit or restyle and the references after it: URLs, data URLs or paths of this machine
	Image      string
	References []string
	// High resolution pass asked for, nil for the model's default
	Upscale *bool
	// Creative controls the call gave that the service takes, by name
	Controls map[string]any
	// Arguments of the service's own, the call's over the person's, checked against its schema
	Arguments map[string]any
	// Model the service's own setting names, empty for its default
	Model string
}

One image_generate call as a service is asked it

func (ImageRequest) Sources

func (r ImageRequest) Sources(limit int) []string

Pictures a call hands a service, the main one first

type ImageTakes

type ImageTakes struct {
	// Edits or restyles the pictures it is handed, besides drawing from text
	Edits bool
	// Most pictures it takes in all, the main one and its references
	References int
	// Takes the high resolution pass of image_generate's upscale
	Upscale bool
	// Creative controls it takes, of Controls
	Controls []string
	// The pictures it is handed give the look only, they are not edited
	Style bool
	// What the pickers say of the service as the settings have it, such as what its storage keeps
	Notes []string
	// Arguments of its own beyond those every service shares, such as steps, guidance or a style of its own: a JSON schema of an object
	// whose properties image_generate offers the model, a call checked against it before the service is asked; nil for none
	Arguments map[string]any
	// Values of its own arguments a person set on its page, which a call's own replace
	Defaults map[string]any
	// Factors its upscale enlarges a picture by, the first the one taken when a call names none
	Factors []int
}

What the picture model of a service takes

func (ImageTakes) Checked

func (t ImageTakes) Checked(service string, given map[string]any) (map[string]any, error)

The service's own arguments a call hands it: the values the person set on its page, the call's own over them, each checked against the schema the service declares before it is asked. Refused in words when the call gives one it does not declare, when its schema can't be read, or when a value does not fit; nil when it declares none and the call gives none

func (ImageTakes) Factor

func (t ImageTakes) Factor(service string, asked int) (int, error)

Factor an upscale enlarges a picture by: the one a call asks when the service takes it, else the first it takes; refused in words when the service upscales nothing or takes no such factor

func (ImageTakes) Properties

func (t ImageTakes) Properties() map[string]map[string]any

Properties of the service's own arguments by name, a name image_generate gives every service left out

type Images

type Images struct {
	// What it draws and how, a line for the picker
	About string
	// Section of its settings for pictures, whose page is its page under Images
	Section string
	// Setting of its own that names the model it draws with, empty for its default: the one model of the service
	Model string
	// Models it draws with, as the picker lists them, and the one it uses when no setting names one
	Models  func(ctx context.Context, cfg *config.Config) []Model
	Default func(ctx context.Context, cfg *config.Config) string
	// What the model it would draw with takes, which shapes the arguments of image_generate
	Takes    func(cfg *config.Config) ImageTakes
	Generate func(ctx context.Context, job *Job, request ImageRequest) Result
	// Enlarges a picture it is handed by one of the factors its Takes names, which image_upscale offers; nil for a service that upscales
	// nothing
	Upscale func(ctx context.Context, job *Job, request UpscaleRequest) Result
}

Pictures of a service

type Job

type Job struct {
	Config *config.Config
	// Told of the tokens a call billed by them took and the route it went to; nil when nobody counts them
	Used func(route provider.Route, usage provider.Usage)
	// Why a file of this machine the job is asked to read may not be read, as the tools guard the reads of the profile; nil where nothing
	// guards them
	Guard func(path string) string
	// Told how far a job that takes a while got: done out of total, total nil when not known, and what it does now; nil where nobody
	// watches
	Progress func(done float64, total *float64, message string)
}

What a service is handed to make one picture or video

func (*Job) Download

func (j *Job) Download(ctx context.Context, kind Kind, raw string, f Fetch) (string, error)

Streams a URL a service answered with into the cache of the kind, no partial file left behind, every hop checked against the private address rules except one on the service's own endpoint; a data URL is decoded into it

func (*Job) Fetch

func (j *Job) Fetch(ctx context.Context, address string, timeout time.Duration, max int64) ([]byte, error)

Bytes at an http(s) URL whose host passes the private address rules, redirects checked the same way, at most max bytes

func (*Job) Local

func (j *Job) Local(path string) ([]byte, error)

Bytes of a file of this machine a call names, ~ expanded, refused when it is one of icebath's credential stores, token folders or an env file, or no regular file

func (*Job) Picture

func (j *Job) Picture(ctx context.Context, call Call, b64, address, prefix, label, origin string) (string, *Result)

Picture an images API answered with kept in the cache: its base64, else its URL downloaded, the URL itself when the download fails; a failure of the call when it carried neither or the base64 could not be saved. Label names the service in what the model reads

func (*Job) Read

func (j *Job) Read(ctx context.Context, source string) ([]byte, string, error)

Bytes and file name of a source of any form: a URL fetched under the private address rules, a data URL, or a file of this machine

func (*Job) Record

func (j *Job) Record(route provider.Route, report any)

Records the tokens a call took when it reported any

func (*Job) Report

func (j *Job) Report(percent float64, message string)

Tells whoever watches the job how far it got, a percent from 0 to 100 or below 0 when not known, and what it does now

func (*Job) Save

func (j *Job) Save(kind Kind, data []byte, prefix, extension string) (string, error)

Saves the bytes into the cache of the kind, answering the path

func (*Job) Unpack

func (j *Job) Unpack(kind Kind, b64, prefix, extension string) (string, error)

Saves base64 data into the cache of the kind, answering the path

func (*Job) Unreadable

func (j *Job) Unreadable(path string) string

Why the job may not read a file of this machine, the refusal of the tools that guard reads, such as of icebath's credential stores, token folders and env files; empty when it may or nothing guards the job's reads

type Kind

type Kind string

What a service makes

const (
	Image Kind = "image"
	Video Kind = "video"
)

type Model

type Model struct {
	ID        string
	Title     string
	Speed     string
	Strengths string
	Price     string
	// What it makes videos from, text and image; its lengths in seconds, zero when not known
	Modalities  []string
	MinDuration int
	MaxDuration int
}

One model of a service as the pickers list it

type OpenAI

type OpenAI struct {
	BaseURL string
	Key     string
	// Headers every request carries, such as OpenAI-Organization
	Headers map[string]string
	// Environment of the profile the requests are for, which names their proxy and the authorities they trust: no proxy and the system's
	// authorities alone when nil
	Env httpx.Env
}

Client of the images and videos APIs of OpenAI and of the services that copy them, such as DeepInfra and Meta

func (OpenAI) Content

func (c OpenAI) Content(ctx context.Context, id string) ([]byte, error)

Bytes of the video a finished job made

func (OpenAI) CreateVideo

func (c OpenAI) CreateVideo(ctx context.Context, body map[string]any) (map[string]any, error)

Starts a video job: POST videos with the JSON body

func (OpenAI) Edit

func (c OpenAI) Edit(ctx context.Context, fields map[string]any, images []Upload) (map[string]any, error)

Edits pictures: POST images/edits as a form, one image as image and several as image[]

func (OpenAI) Images

func (c OpenAI) Images(ctx context.Context, body map[string]any) (map[string]any, error)

Draws pictures: POST images/generations with the JSON body

func (OpenAI) Video

func (c OpenAI) Video(ctx context.Context, id string) (map[string]any, error)

State of a video job

type Refusal

type Refusal struct{ Text string }

Refusal of a source a service reads, worded for the model

func (*Refusal) Error

func (e *Refusal) Error() string

type Registrant

type Registrant interface {
	// Services of the profile of the settings, such as those the extensions it installed bring besides the ones every profile has
	Services(cfg *config.Config) []Service
}

type Registry

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

func (*Registry) Active

func (r *Registry) Active(cfg *config.Config, kind Kind) (Service, error)

Service that makes the kind with the settings: the one chosen, set up or not, else the first set up; an error the model reads when the one chosen is not registered or none is set up

func (*Registry) Choose

func (r *Registry) Choose(cfg *config.Config, kind Kind, name string) error

Uses the service of the name for things of the kind, the model it has kept as it was; the first service that is ready for no name. A name no service of the kind has is refused in a person's words

func (*Registry) Host

func (r *Registry) Host() *Generation

Host the registry is nested in, through which plugins reach every service

func (*Registry) Making

func (r *Registry) Making(cfg *config.Config, kind Kind) []Service

Services of the profile that make the kind

func (*Registry) Note

func (r *Registry) Note(cfg *config.Config, kind Kind, name string) string

What a choice of service says once it is kept, Automatic for no name

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

func (*Registry) Service

func (r *Registry) Service(cfg *config.Config, kind Kind, name string) (Service, bool)

Service of the profile with the name that makes the kind

func (*Registry) Services

func (r *Registry) Services(cfg *config.Config) []Service

Every service of the profile of the settings, in the order they were registered, one whose name an earlier service has left out so an extension never shadows a built in one. A service of a kind without the section of its page or the setting of its model is a mistake of the code

func (*Registry) Standing

func (r *Registry) Standing(cfg *config.Config, kind Kind) Standing

How the services of the kind stand for the profile, every service of it listed and asked whether it is set up once

type Result

type Result struct {
	OK bool
	// File the picture or video was saved to, else the address it is fetched from
	Media string
	// Copy kept in the cache of what Media is the address of, such as a picture stored at the service for a link to chain into its tools
	Copy     string
	Model    string
	Prompt   string
	Aspect   string
	Provider string
	// What it was made from: text, image, or reference for videos made from references
	Modality string
	// Seconds of a video
	Duration int
	// Why it failed and what kind of failure it was, such as auth_required
	Error string
	Type  string
	// Fields a service adds, such as the revised prompt or the storage link
	Extra map[string]any
}

What a call made, or why it failed, as the model reads it

func (Result) Envelope

func (r Result) Envelope(kind Kind) map[string]any

The result as the model reads it: the picture under image or the video under video, the fields of the service after those of the call

type Service

type Service struct {
	// As image_gen.provider and video_gen.provider name it
	Name  string
	Title string
	// Whether it can be used with the settings, its key or sign-in there
	Ready func(cfg *config.Config) bool
	// How a person sets it up
	Setup  Setup
	Images *Images
	Videos *Videos
}

A service that draws pictures, makes videos or both, what a generation plugin registers

func (Service) About

func (s Service) About(kind Kind) string

What it makes of the kind and how, a line for the pickers

func (Service) Makes

func (s Service) Makes(kind Kind) bool

Whether the service makes the kind

func (Service) Model

func (s Service) Model(cfg *config.Config, kind Kind) string

Model its own setting names for the kind, empty for its default

func (Service) ModelSetting

func (s Service) ModelSetting(kind Kind) string

Setting of its own that names its model for the kind, empty for a kind it does not make

func (Service) Section

func (s Service) Section(kind Kind) string

Section of its settings for the kind, whose page is its page

func (Service) Set

func (s Service) Set(cfg *config.Config) bool

Whether it can be used with the settings

type Setup

type Setup struct {
	// Price in a word, free for one that costs nothing
	Badge string
	// Setting of the API key of its own it asks for, empty when it asks for none
	Key string
	// What the key is called and where to get one
	Prompt, Link string
	// Kinds of model provider whose account it uses instead, the first the one a person adds; none for a service with a key of its own
	Providers []string
	// Variables of the profile it needs set besides, such as those the manifest of an extension names; none for a service that needs no more
	Needs []string
}

What a person sets up to use a service

type Standing

type Standing struct {
	// Services of the profile that make the kind, in their order
	Services []Service
	// Whether each service is set up, by its place in Services
	Set []bool
	// contains filtered or unexported fields
}

How the services of a kind stand for a profile, read once: the services that make it, each asked once whether it is set up, and the one Active picks among them

func (Standing) Hindrance

func (s Standing) Hindrance() string

What keeps the agent from making things of the kind, a sentence; empty when nothing does or the person turned them off

func (Standing) Serving

func (s Standing) Serving() string

Name of the service that makes things of the kind for the agent now, empty while none does: videos turned off, the service chosen not there or not ready, or none ready

func (Standing) State

func (s Standing) State(i int) State

How the service at the place in Services stands: in use while it makes things of the kind for the agent, else ready, free or what it lacks

type State

type State int

How a service stands for a profile, in the words every page and message says it in

const (
	// Makes things of the kind for the agent now
	InUse State = iota
	// Its key or account is there
	Ready
	// Ready, and costs nothing
	Free
	// Lacks the API key of its own it asks for
	NeedsKey
	// Lacks the account at a provider it uses
	NotConnected
	// Lacks variables of the profile it needs, such as those an extension asks for
	NeedsSetup
)

func (State) String

func (s State) String() string

type Unregistered

type Unregistered struct {
	Kind Kind
	Name string
}

Service chosen in the settings that no plugin registers

func (*Unregistered) Error

func (e *Unregistered) Error() string

type Upload

type Upload struct {
	Name string
	Data []byte
}

One file of an images edit

type UpscaleRequest

type UpscaleRequest struct {
	// Picture to enlarge: a URL, a data URL or a path of this machine
	Image string
	// Times it is enlarged, one of the factors the service takes
	Factor int
	// What the picture shows, which some upscalers sharpen by; empty for none
	Prompt string
	// Model the service's own setting names, empty for its default
	Model string
}

One image_upscale call as a service is asked it

type VideoRequest

type VideoRequest struct {
	Prompt string
	// Model the service's own setting names, empty for its default
	Model string
	// Still to animate, and reference pictures: URLs, data URLs or paths of this machine
	Image      string
	References []string
	// Seconds asked for, nil for the model's default
	Duration *int
	// Aspect ratio and resolution asked for, 16:9 and 720p when the call named none
	Aspect     string
	Resolution string
	Negative   string
	Audio      *bool
	Seed       *int
	Upscale    *bool
}

One video_generate call as a service is asked it

type VideoTakes

type VideoTakes struct {
	// What it makes videos from: text, image
	Modalities  []string
	Aspects     []string
	Resolutions []string
	MinDuration int
	MaxDuration int
	// Takes the audio toggle, makes audio with every video whatever is asked, takes a negative prompt, a seed, the upscale pass
	Audio, AudioAlways, Negative, Seed, Upscale bool
	// Most reference pictures it takes
	References int
	// Lines the description of video_generate and the pickers add for it, such as how its videos chain into its own edit tools
	Notes []string
}

What the video model of a service takes

type Videos

type Videos struct {
	About string
	// Section of its settings for videos, whose page is its page under Videos
	Section string
	// Setting of its own that names the model it makes videos with, empty for its default: the one model of the service
	Model   string
	Models  func(ctx context.Context, cfg *config.Config) []Model
	Default func(ctx context.Context, cfg *config.Config) string
	// What the model it would make videos with takes, which shapes the arguments of video_generate
	Takes    func(cfg *config.Config) VideoTakes
	Generate func(ctx context.Context, job *Job, request VideoRequest) Result
}

Videos of a service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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