Documentation
¶
Index ¶
- Constants
- Variables
- func Aspect(text string) string
- func Base64(text string) ([]byte, error)
- func Chosen(cfg *config.Config, kind Kind) string
- func DataURL(mime string, data []byte) string
- func Dir(cfg *config.Config, kind Kind) (string, error)
- func Get(ctx context.Context, env httpx.Env, address string, headers map[string]string, ...) (map[string]any, error)
- func Idle(r io.Reader, limit time.Duration, cancel context.CancelFunc) ([]byte, error)
- func Inline(source string) ([]byte, string, error)
- func List(value any, key string) []any
- func Message(_ int, body []byte) string
- func Object(value any) map[string]any
- func On(cfg *config.Config, kind Kind) bool
- func Remote(source string) bool
- func SetVideos(cfg *config.Config, on bool) error
- func Shared(name string) bool
- func Size(aspect string) string
- func Sniff(data []byte) string
- func Status(code int, address string) error
- func Text(value any, key string) string
- func TypeOf(name string) string
- func Usage(report any) (provider.Usage, bool)
- func Whole(value any) *int
- type Call
- type Catalogs
- type Failure
- type Fetch
- type Generation
- type ImageRequest
- type ImageTakes
- type Images
- type Job
- func (j *Job) Download(ctx context.Context, kind Kind, raw string, f Fetch) (string, error)
- func (j *Job) Fetch(ctx context.Context, address string, timeout time.Duration, max int64) ([]byte, error)
- func (j *Job) Local(path string) ([]byte, error)
- func (j *Job) Picture(ctx context.Context, call Call, b64, address, prefix, label, origin string) (string, *Result)
- func (j *Job) Read(ctx context.Context, source string) ([]byte, string, error)
- func (j *Job) Record(route provider.Route, report any)
- func (j *Job) Report(percent float64, message string)
- func (j *Job) Save(kind Kind, data []byte, prefix, extension string) (string, error)
- func (j *Job) Unpack(kind Kind, b64, prefix, extension string) (string, error)
- func (j *Job) Unreadable(path string) string
- type Kind
- type Model
- type OpenAI
- func (c OpenAI) Content(ctx context.Context, id string) ([]byte, error)
- func (c OpenAI) CreateVideo(ctx context.Context, body map[string]any) (map[string]any, error)
- func (c OpenAI) Edit(ctx context.Context, fields map[string]any, images []Upload) (map[string]any, error)
- func (c OpenAI) Images(ctx context.Context, body map[string]any) (map[string]any, error)
- func (c OpenAI) Video(ctx context.Context, id string) (map[string]any, error)
- type Refusal
- type Registrant
- type Registry
- func (r *Registry) Active(cfg *config.Config, kind Kind) (Service, error)
- func (r *Registry) Choose(cfg *config.Config, kind Kind, name string) error
- func (r *Registry) Host() *Generation
- func (r *Registry) Making(cfg *config.Config, kind Kind) []Service
- func (r *Registry) Note(cfg *config.Config, kind Kind, name string) string
- func (r *Registry) Register(registrant Registrant)
- func (r *Registry) Service(cfg *config.Config, kind Kind, name string) (Service, bool)
- func (r *Registry) Services(cfg *config.Config) []Service
- func (r *Registry) Standing(cfg *config.Config, kind Kind) Standing
- type Result
- type Service
- type Setup
- type Standing
- type State
- type Unregistered
- type Upload
- type UpscaleRequest
- type VideoRequest
- type VideoTakes
- type Videos
Constants ¶
const ( DefaultVideoAspect = "16:9" DefaultVideoResolution = "720p" )
const DefaultAspect = "landscape"
const Generated = "cache/generated"
Folder of the profile what the services make is kept in, under the caches a sandbox is handed
const (
// Address of OpenAI's API, where an OpenAI client goes when given none
OpenAIBase = "https://api.openai.com/v1"
)
const Retry = 30 * time.Second
How long a catalog read that failed is kept before the service is asked again
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 ¶
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
var Agent = provider.UserAgent("Icebath-Agent")
Name the services are told the calls come from
var Aspects = []string{"landscape", "square", "portrait"}
Shapes of picture image_generate takes, landscape when the call names another
var Controls = []string{"creativity", "thinking", "resolution", "intensity", "complexity", "movement"}
Creative controls a picture model may take, in the order image_generate lists them
var ErrUnsafe = errors.New("URL failed the SSRF safety check")
Refusal of a URL whose host is private or internal
Functions ¶
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 ¶
Body of a reply with every wait for more bounded by the limit, the request cancelled when one runs out
func Message ¶
Message of a failed JSON reply: its error's message, else the first 300 characters of the body
func On ¶
Whether the agent makes things of the kind at all: images always, videos only while Videos is on
func SetVideos ¶
Turns the making of videos on or off, the one control of whether the agent makes them
func Shared ¶
Whether image_generate gives every service an argument of the name, so no service's own argument may take it
func Size ¶
Size the OpenAI images API and those that copy it take for the shape, square for an unknown one
func Sniff ¶
Type of an image from its first bytes, empty when it is none of png, jpeg, gif, webp, bmp, tiff, avif, heic or svg
Types ¶
type Call ¶
type Call struct {
Provider, Model, Prompt, Aspect string
}
Fields every result of one call carries
type Catalogs ¶
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
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
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 ¶
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 ¶
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 ¶
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 ¶
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) Report ¶
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) Unreadable ¶
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 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) CreateVideo ¶
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[]
type Refusal ¶
type Refusal struct{ Text string }
Refusal of a source a service reads, worded for the model
type Registrant ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Active ¶
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 ¶
Uses the service of the name for things of the kind, the model it has kept as it was; Automatic for auto, and for no name, which a reset of the setting writes. 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) Register ¶
func (r *Registry) Register(registrant Registrant)
func (*Registry) Services ¶
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
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
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) ModelSetting ¶
Setting of its own that names its model for the kind, empty for a kind it does not make
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 ¶
What keeps the agent from making things of the kind, a sentence; empty when nothing does or the person turned them off
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 )
type Unregistered ¶
Service chosen in the settings that no plugin registers
func (*Unregistered) Error ¶
func (e *Unregistered) Error() string
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