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 ¶
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 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) MarshalJSON ¶
func (*Options) UnmarshalJSON ¶
type Output ¶
type Output struct {
Media *media.Media `json:"media,omitzero"`
Metadata metadata.Map `json:"metadata,omitzero"`
}
func (Output) MarshalJSON ¶
func (*Output) UnmarshalJSON ¶
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) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
type ResponseMetadata ¶
type ResponseMetadata struct {
CreatedAt time.Time `json:"created_at,omitzero"`
Extra metadata.Map `json:"extra,omitzero"`
}
func (ResponseMetadata) MarshalJSON ¶
func (r ResponseMetadata) MarshalJSON() ([]byte, error)
func (*ResponseMetadata) UnmarshalJSON ¶
func (r *ResponseMetadata) UnmarshalJSON(data []byte) error