Documentation
¶
Overview ¶
Package object defines provider-agnostic types and the Provider interface for object generation operations.
This package sits at the innermost domain layer and must not depend on any other internal pkg/ packages. Providers implement the Provider interface to translate between their API and the request/response types declared here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoProvider indicates the Client has no underlying Provider configured. ErrNoProvider = errors.New("object: no provider configured") // ErrInvalidRequest indicates the Request is malformed or missing // required fields. ErrInvalidRequest = errors.New("object: invalid request") // unreachable or returned a transient failure. ErrProviderUnavailable = errors.New("object: provider unavailable") // ErrRateLimited indicates the upstream provider rejected the request due // to rate limiting or quota exhaustion. ErrRateLimited = errors.New("object: rate limited") // ErrAuthFailed indicates the provider rejected the supplied credentials. ErrAuthFailed = errors.New("object: authentication failed") // ErrUnsupported indicates the provider does not support a requested // capability. ErrUnsupported = errors.New("object: unsupported operation") )
Functions ¶
func ProviderOptionsFor ¶
ProviderOptionsFor extracts a provider-specific options bucket from a ProviderOptions map (typically Request.ProviderOptions) into a typed value. Behaviour mirrors the helpers used in other domain packages: if the bucket is already of type T it is returned as-is; if it is a plain map it will be JSON round-tripped into T so struct tags are honoured.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin, provider-agnostic facade over a Provider. It centralises concerns that are independent of the underlying backend and nil-guards provider calls for callers.
func NewClient ¶
NewClient returns a Client backed by the given Provider. The Provider may be nil; in that case the Client's methods will return ErrNoProvider.
func (*Client) GenerateObject ¶
GenerateObject performs a non-streaming object generation request. If the Client or its Provider is nil, ErrNoProvider is returned.
func (*Client) StreamObject ¶
StreamObject performs a streaming object generation request. If the Client or its Provider is nil, ErrNoProvider is returned. The caller must Close the returned ObjectStream when finished.
type Object ¶
Object is a simple named artefact produced by providers. Name is a short identifier (for example a filename) and Content holds the textual payload.
type ObjectChunk ¶
type ObjectChunk struct {
// Delta is the JSON patch or partial object text.
Delta string `json:"delta"`
// Done is true when the stream is complete.
Done bool `json:"done"`
}
ObjectChunk is a partial object emitted during streaming.
type ObjectResult ¶
type ObjectResult any
ObjectResult is the abstract result returned by providers. It is kept as an alias for any so provider implementations may return either a concrete Object or any richer structure without forcing a single shape across providers.
type ObjectStream ¶
type ObjectStream interface {
// Next returns the next chunk. It returns io.EOF when the stream is
// exhausted.
Next(ctx context.Context) (ObjectChunk, error)
// Close releases resources associated with the stream.
Close() error
}
ObjectStream is an iterator over object chunks.
type Provider ¶
type Provider interface {
// Name returns a short, stable identifier for the provider
// (for example, "openai", "ollama").
Name() string
// GenerateObject performs a non-streaming object generation operation.
GenerateObject(ctx context.Context, req Request) (ObjectResult, error)
// StreamObject performs a streaming object generation. Callers must
// Close the returned ObjectStream when finished.
StreamObject(ctx context.Context, req Request) (ObjectStream, error)
}
Provider is implemented by object generation backends. Implementations translate between the provider-agnostic Request/Response types defined in this package and their underlying API.
type Request ¶
type Request struct {
Model string `json:"model"`
Prompt string `json:"prompt,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
ProviderOptions map[string]any `json:"provider_options,omitempty"`
}
Request is a provider-agnostic object generation request. Only Model is required by convention; providers should treat zero values as "unspecified" and apply their own defaults.
type Response ¶
type Response struct {
ID string `json:"id,omitempty"`
Model string `json:"model,omitempty"`
Object Object `json:"object"`
Warnings []Warning `json:"warnings,omitempty"`
}
Response is a non-streaming object generation result.
type UnsupportedContentError ¶
UnsupportedContentError is an optional typed error carrying context about unsupported content. It unwraps to ErrUnsupported to allow errors.Is.
func (*UnsupportedContentError) Error ¶
func (e *UnsupportedContentError) Error() string
func (*UnsupportedContentError) Unwrap ¶
func (e *UnsupportedContentError) Unwrap() error