image

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package image defines the serializable image-generation protocol and its single-method Model capability.

NewRequest captures the prompt; Options carries shared per-call overrides such as dimensions, negative prompt, seed, and output MIME type. Outputs use media.Media and preserve every image returned by the provider. Provider-only options use Options.SetExtension so Extensions remains JSON-safe; Request has no arbitrary parameter bag. Implementations and defaults live outside Core.

Example
package main

import (
	"fmt"

	"github.com/Tangerg/scope/core/image"
)

func main() {
	request, err := image.NewRequest("A scope walking through snow")
	if err != nil {
		panic(err)
	}
	options := image.Options{Model: "image-model"}
	err = options.Validate()
	if err != nil {
		panic(err)
	}
	options.OutputFormat = "image/png"
	request.Options = options

	fmt.Println(request.Options.Model, request.Options.OutputFormat)
}
Output:
image-model image/png

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOptions  = errors.New("image: invalid options")
	ErrInvalidRequest  = errors.New("image: invalid request")
	ErrInvalidResponse = errors.New("image: invalid response")
)

Functions

This section is empty.

Types

type Model

type Model interface {
	// Call performs one image-generation request after validating all prompt and
	// option invariants. It must not retain or mutate request and transfers
	// ownership of the provider-neutral response to the caller. Context
	// cancellation remains identifiable through errors.Is.
	Call(ctx context.Context, request *Request) (*Response, error)
}

Model is the complete provider-neutral image generation SPI. Call implementations validate requests before I/O, reject explicit options they cannot represent, preserve context error identity, and return responses that pass Validate. Provider defaults and identity belong to provider construction and observability.

type ModelFunc

type ModelFunc func(context.Context, *Request) (*Response, error)

func (ModelFunc) Call

func (m ModelFunc) Call(ctx context.Context, request *Request) (*Response, error)

type Options

type Options struct {
	// Model is the provider model identifier (e.g. "dall-e-3").
	Model string `json:"model"`

	// NegativePrompt describes what should not appear in the image.
	NegativePrompt string `json:"negative_prompt"`

	// Width / Height set the output dimensions in pixels.
	Width  *int64 `json:"width,omitempty"`
	Height *int64 `json:"height,omitempty"`

	// Seed pins the RNG so repeated calls produce the same image.
	Seed *int64 `json:"seed,omitempty"`

	// OutputFormat picks the image MIME type of the rendered bytes.
	// Empty leaves the format to the provider.
	OutputFormat string `json:"output_format,omitempty"`

	// Extensions carries JSON-safe provider-specific options unknown to this
	// struct.
	Extensions metadata.Extensions `json:"extensions,omitzero"`
}

Options holds per-request configuration for an image-generation call. Pointer fields preserve the distinction between an override and a provider default. Resolve snapshots mutable values and overlays only fields explicitly supplied by the request.

func (Options) Clone

func (o Options) Clone() Options

func (Options) MarshalJSON

func (o Options) MarshalJSON() ([]byte, error)

func (Options) Resolve

func (o Options) Resolve(override Options) (Options, error)

func (*Options) UnmarshalJSON

func (o *Options) UnmarshalJSON(data []byte) error

func (Options) Validate

func (o Options) Validate() error

type Output

type Output struct {
	// Media holds the generated image as bytes or an absolute URI.
	Media *media.Media `json:"media,omitempty"`

	// Metadata carries per-image extras.
	Metadata metadata.Map `json:"metadata,omitzero"`
}

Output is one generated image plus its metadata.

func NewOutput

func NewOutput(value *media.Media, outputMetadata metadata.Map) (*Output, error)

func (Output) MarshalJSON

func (o Output) MarshalJSON() ([]byte, error)

func (*Output) UnmarshalJSON

func (o *Output) UnmarshalJSON(data []byte) error

func (*Output) Validate

func (o *Output) Validate() error

type Request

type Request struct {
	// Prompt is the natural-language description of the desired image.
	Prompt string `json:"prompt"`

	Options Options `json:"options,omitzero"`
}

Request is one image-generation call: the prompt and explicit options.

func NewRequest

func NewRequest(prompt string) (*Request, error)

func (Request) MarshalJSON

func (r Request) MarshalJSON() ([]byte, error)

func (*Request) UnmarshalJSON

func (r *Request) UnmarshalJSON(data []byte) error

func (*Request) Validate

func (r *Request) Validate() error

type Response

type Response struct {
	// Outputs contains every image returned by the provider, in provider order.
	Outputs []*Output `json:"outputs,omitzero"`

	// Metadata carries shared response-level fields.
	Metadata *ResponseMetadata `json:"metadata,omitempty"`
}

Response is the full image-generation output: every rendered image plus shared response metadata.

func NewResponse

func NewResponse(outputs []*Output, metadata *ResponseMetadata) (*Response, error)

func (*Response) First

func (r *Response) First() *Output

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

func (*Response) Validate

func (r *Response) Validate() error

type ResponseMetadata

type ResponseMetadata struct {
	// Created is the provider-reported creation time, Unix seconds.
	Created int64 `json:"created"`

	// Extra carries JSON-safe provider-specific metadata.
	Extra metadata.Map `json:"extra,omitzero"`
}

ResponseMetadata holds response-level metadata for an image generation request.

func (ResponseMetadata) MarshalJSON

func (r ResponseMetadata) MarshalJSON() ([]byte, error)

func (*ResponseMetadata) UnmarshalJSON

func (r *ResponseMetadata) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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