inference

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package inference defines provider-neutral generation, embedding, token, and usage contracts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProbeTextModel

func ProbeTextModel(ctx context.Context, model TextModel) error

ProbeTextModel sends the smallest provider-neutral generation request. It intentionally bypasses structured generation, tracing, usage reporting, and prompt assets; the caller owns the wall-clock timeout and result cache.

Types

type BatchedEmbeddingModel

type BatchedEmbeddingModel struct {
	// contains filtered or unexported fields
}

func NewBatchedEmbeddingModel

func NewBatchedEmbeddingModel(
	transport EmbeddingTransport,
	profile EmbeddingProfile,
	batchSize int,
	limits *Limits,
) (*BatchedEmbeddingModel, error)

func (*BatchedEmbeddingModel) Embed

func (*BatchedEmbeddingModel) Profile

type ConfigurationError

type ConfigurationError struct {
	// contains filtered or unexported fields
}

ConfigurationError reports a stable, non-transient inference configuration failure. A wrapped provider cause is available only through errors.Is/As and is never interpolated into the stable Error value.

func NewConfigurationError

func NewConfigurationError(code, detail string) *ConfigurationError

func WrapConfigurationError

func WrapConfigurationError(code, detail string, cause error) *ConfigurationError

WrapConfigurationError retains the provider or SDK error for errors.Is/As without allowing its potentially sensitive text into the stable Error value.

func (*ConfigurationError) Code

func (e *ConfigurationError) Code() string

func (*ConfigurationError) Detail

func (e *ConfigurationError) Detail() string

func (*ConfigurationError) Error

func (e *ConfigurationError) Error() string

func (*ConfigurationError) Unwrap

func (e *ConfigurationError) Unwrap() error

type EmbeddingInputType

type EmbeddingInputType string
const (
	EmbeddingDocument EmbeddingInputType = "document"
	EmbeddingQuery    EmbeddingInputType = "query"
)

type EmbeddingModel

type EmbeddingModel interface {
	Profile() EmbeddingProfile
	Embed(context.Context, []string) (EmbeddingResult, error)
}

type EmbeddingProfile

type EmbeddingProfile interface {
	ID() string
	ModelName() string
	DimensionCount() int
	NormalizationMode() string
}

type EmbeddingRequest

type EmbeddingRequest struct {
	// contains filtered or unexported fields
}

func NewEmbeddingRequest

func NewEmbeddingRequest(inputs []string, inputType EmbeddingInputType, dimension int) (EmbeddingRequest, error)

func (EmbeddingRequest) DimensionCount

func (r EmbeddingRequest) DimensionCount() int

func (EmbeddingRequest) InputType

func (r EmbeddingRequest) InputType() EmbeddingInputType

func (EmbeddingRequest) Inputs

func (r EmbeddingRequest) Inputs() []string

type EmbeddingResult

type EmbeddingResult struct {
	Vectors [][]float64
	Usage   Usage
}

type EmbeddingTransport

type EmbeddingTransport interface {
	Embed(context.Context, EmbeddingRequest) (ProviderEmbeddingResult, error)
}

func TraceEmbeddingTransport

func TraceEmbeddingTransport(transport EmbeddingTransport, provider trace.TracerProvider) EmbeddingTransport

TraceEmbeddingTransport instruments each provider batch while leaving the batching, validation, normalization, and total timeout under BatchedEmbeddingModel's ownership.

type GenerationResult

type GenerationResult[T any] struct {
	Output T
	Usage  Usage
}

type GenerationSettings

type GenerationSettings struct {
	// contains filtered or unexported fields
}

func NewGenerationSettings

func NewGenerationSettings(temperature *float64, maxTokens *int64) (GenerationSettings, error)

func (GenerationSettings) MaxTokens

func (s GenerationSettings) MaxTokens() *int64

func (GenerationSettings) Temperature

func (s GenerationSettings) Temperature() *float64

type InvalidOutputError

type InvalidOutputError struct {
	// contains filtered or unexported fields
}

InvalidOutputError reports a provider result that violated the capability contract. Detail is intentionally bounded and must not contain provider response bodies, prompts, or user content.

func NewInvalidOutputError

func NewInvalidOutputError(operation, detail string) *InvalidOutputError

func (*InvalidOutputError) Detail

func (e *InvalidOutputError) Detail() string

func (*InvalidOutputError) Error

func (e *InvalidOutputError) Error() string

func (*InvalidOutputError) Operation

func (e *InvalidOutputError) Operation() string

type JSONCodec

type JSONCodec[I, O any] struct {
	// contains filtered or unexported fields
}

func NewJSONCodec

func NewJSONCodec[I, O any](
	schema []byte,
	encode func(I) ([]byte, error),
	decode func([]byte) (O, error),
) (*JSONCodec[I, O], error)

func (*JSONCodec[I, O]) DecodeOutput

func (c *JSONCodec[I, O]) DecodeOutput(value []byte) (O, error)

func (*JSONCodec[I, O]) EncodeInput

func (c *JSONCodec[I, O]) EncodeInput(value I) ([]byte, error)

func (*JSONCodec[I, O]) OutputSchema

func (c *JSONCodec[I, O]) OutputSchema() []byte

type Limits

type Limits struct {
	// contains filtered or unexported fields
}

func DefaultLimits

func DefaultLimits() Limits

func NewLimits

func NewLimits(timeout time.Duration, maxRequests int) (Limits, error)

func (Limits) MaxRequests

func (l Limits) MaxRequests() int

func (Limits) Timeout

func (l Limits) Timeout() time.Duration

type Message

type Message struct {
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(role MessageRole, content string) (Message, error)

func (Message) Content

func (m Message) Content() string

func (Message) ResponseIdentity

func (m Message) ResponseIdentity() *ResponseIdentity

func (Message) Role

func (m Message) Role() MessageRole

type MessageRole

type MessageRole uint8
const (
	RoleUser MessageRole = iota + 1
	RoleAssistant
)

type PromptedGenerator

type PromptedGenerator[I, O any] struct {
	// contains filtered or unexported fields
}

func NewPromptedGenerator

func NewPromptedGenerator[I, O any](
	model TextModel,
	instructions string,
	codec StructuredCodec[I, O],
	limits *Limits,
	settings GenerationSettings,
) (*PromptedGenerator[I, O], error)

func (*PromptedGenerator[I, O]) Generate

func (g *PromptedGenerator[I, O]) Generate(ctx context.Context, value I) (GenerationResult[O], error)

type ProviderEmbeddingResult

type ProviderEmbeddingResult struct {
	// contains filtered or unexported fields
}

func NewProviderEmbeddingResult

func NewProviderEmbeddingResult(
	inputs []string,
	inputType EmbeddingInputType,
	embeddings [][]float64,
	usage Usage,
) (ProviderEmbeddingResult, error)

func (ProviderEmbeddingResult) Embeddings

func (r ProviderEmbeddingResult) Embeddings() [][]float64

func (ProviderEmbeddingResult) InputType

func (ProviderEmbeddingResult) Inputs

func (r ProviderEmbeddingResult) Inputs() []string

func (ProviderEmbeddingResult) Usage

func (r ProviderEmbeddingResult) Usage() Usage

type ResponseIdentity

type ResponseIdentity struct {
	// contains filtered or unexported fields
}

ResponseIdentity carries the minimum provider-generated identity needed to replay an assistant turn without retaining an entire provider response.

func NewResponseIdentity

func NewResponseIdentity(protocol, itemID string) (ResponseIdentity, error)

func (ResponseIdentity) ItemID

func (i ResponseIdentity) ItemID() string

func (ResponseIdentity) Protocol

func (i ResponseIdentity) Protocol() string

type StructuredCodec

type StructuredCodec[I, O any] interface {
	EncodeInput(I) ([]byte, error)
	OutputSchema() []byte
	DecodeOutput([]byte) (O, error)
}

StructuredCodec keeps wire JSON and validation rules separate from domain values. Implementations must never return partially validated output.

type StructuredGenerator

type StructuredGenerator[I, O any] interface {
	Generate(context.Context, I) (GenerationResult[O], error)
}

type TextModel

type TextModel interface {
	Complete(context.Context, TextRequest) (TextResponse, error)
}

TextModel is the deliberately narrow provider contract consumed by the PromptedOutput-compatible structured generator.

func TraceTextModel

func TraceTextModel(model TextModel, provider trace.TracerProvider) TextModel

TraceTextModel instruments one physical provider request. The span contract deliberately contains no prompt, message, output, model request parameters, credentials, or provider response bodies.

type TextRequest

type TextRequest struct {
	// contains filtered or unexported fields
}

func (TextRequest) Instructions

func (r TextRequest) Instructions() []string

func (TextRequest) Messages

func (r TextRequest) Messages() []Message

func (TextRequest) Settings

func (r TextRequest) Settings() GenerationSettings

func (TextRequest) StructuredOutput

func (r TextRequest) StructuredOutput() bool

type TextResponse

type TextResponse struct {
	// contains filtered or unexported fields
}

func NewTextResponse

func NewTextResponse(content string, usage Usage) (TextResponse, error)

func (TextResponse) Content

func (r TextResponse) Content() string

func (TextResponse) ResponseIdentity

func (r TextResponse) ResponseIdentity() *ResponseIdentity

func (TextResponse) Usage

func (r TextResponse) Usage() Usage

func (TextResponse) WithResponseIdentity

func (r TextResponse) WithResponseIdentity(identity ResponseIdentity) TextResponse

type TimeoutError

type TimeoutError struct {
	// contains filtered or unexported fields
}

TimeoutError reports that the PowerContext wall-clock budget was exhausted.

func NewTimeoutError

func NewTimeoutError(operation string, timeout time.Duration) *TimeoutError

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

func (*TimeoutError) Operation

func (e *TimeoutError) Operation() string

func (*TimeoutError) Timeout

func (e *TimeoutError) Timeout() time.Duration

type TokenEstimator

type TokenEstimator struct {
	// contains filtered or unexported fields
}

TokenEstimator validates the result of a deployment-fixed token counter.

func CharacterTokenEstimator

func CharacterTokenEstimator() *TokenEstimator

func NewTokenEstimator

func NewTokenEstimator(profile TokenEstimatorProfile, count func(string) int) (*TokenEstimator, error)

func (*TokenEstimator) Estimate

func (e *TokenEstimator) Estimate(text string) (int, error)

func (*TokenEstimator) Profile

type TokenEstimatorProfile

type TokenEstimatorProfile struct {
	// contains filtered or unexported fields
}

TokenEstimatorProfile is the stable deployment identity of a token policy.

func NewTokenEstimatorProfile

func NewTokenEstimatorProfile(estimatorID, version string) (TokenEstimatorProfile, error)

func (TokenEstimatorProfile) EstimatorID

func (p TokenEstimatorProfile) EstimatorID() string

func (TokenEstimatorProfile) Version

func (p TokenEstimatorProfile) Version() string

type UnavailableError

type UnavailableError struct {
	// contains filtered or unexported fields
}

UnavailableError is a transient provider or network failure.

func NewUnavailableError

func NewUnavailableError(operation string) *UnavailableError

func WrapUnavailableError

func WrapUnavailableError(operation string, cause error) *UnavailableError

WrapUnavailableError retains the provider or network error for errors.Is/As while keeping provider response bodies out of the stable Error value.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

func (*UnavailableError) Operation

func (e *UnavailableError) Operation() string

func (*UnavailableError) Unwrap

func (e *UnavailableError) Unwrap() error

type Usage

type Usage struct {
	Requests     int
	InputTokens  *int64
	OutputTokens *int64
}

Usage contains portable successful provider usage fields.

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

func NewValidationError

func NewValidationError(issues []ValidationIssue) (*ValidationError, error)

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Issues

func (e *ValidationError) Issues() []ValidationIssue

type ValidationIssue

type ValidationIssue struct {
	// contains filtered or unexported fields
}

func NewValidationIssue

func NewValidationIssue(kind string, location []any, message string, input json.RawMessage) (ValidationIssue, error)

Jump to

Keyboard shortcuts

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