image

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 11

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.Extensions.Set 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. Implementations reject explicit options they cannot represent and return responses that pass Validate; provider defaults and identity belong to provider construction. Failures use github.com/Tangerg/scope/core/invocation.ClassifyFailure for evidence about the complete call. A nested failure cannot prove that earlier provider work did not run, and no failure kind authorizes retry.

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 string `json:"model"`

	NegativePrompt string `json:"negative_prompt"`

	// Width and Height are in pixels.
	Width  *int64 `json:"width,omitzero"`
	Height *int64 `json:"height,omitzero"`

	Seed *int64 `json:"seed,omitzero"`

	// OutputFormat is a canonical image MIME type; empty leaves it to the provider.
	OutputFormat string `json:"output_format,omitempty"`

	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) JSONSchemaModel added in v0.61.0

func (Options) JSONSchemaModel() any

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 *media.Media `json:"media,omitzero"`

	Metadata metadata.Map `json:"metadata,omitzero"`
}

func NewOutput

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

NewOutput validates and snapshots one provider result before it enters a Response.

func (Output) JSONSchemaModel added in v0.61.0

func (Output) JSONSchemaModel() any

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 string `json:"prompt"`

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

func NewRequest

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

func (Request) JSONSchemaModel added in v0.61.0

func (Request) JSONSchemaModel() any

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 *ResponseMetadata `json:"metadata,omitzero"`
}

func NewResponse

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

func (*Response) First

func (r *Response) First() *Output

func (Response) JSONSchemaModel added in v0.61.0

func (Response) JSONSchemaModel() any

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 {
	CreatedAt time.Time `json:"created_at,omitzero"`

	Extra metadata.Map `json:"extra,omitzero"`
}

func (ResponseMetadata) JSONSchemaModel added in v0.61.0

func (ResponseMetadata) JSONSchemaModel() any

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