compat

package
v0.14.0 Latest Latest
Warning

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

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

Documentation

Overview

Package compat contains the deliberately small shared core used by documented providers whose public endpoint is compatible with one of the bundled request codecs. Provider packages still own identity, defaults, authentication policy, options, and any provider-specific response normalization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(selected model.Model, config Config) (inference.Client, error)

New constructs a transport-backed client for an already validated provider model. The model's APIFormat selects the bundled semantic codec; Path may override the codec's conventional route when a compatible provider uses a documented proxy path.

func NewProvider

func NewProvider(selected model.Model, key auth.APIKey, definition Definition, options ...Option) (inference.Client, error)

NewProvider resolves the selected model's default endpoint, builds the appropriate generic authenticator, and delegates semantic encoding/decoding to New. It supports only AuthNone and AuthAPIKey; special credential providers must use their own constructors.

func NormalizeOpenAIReasoning

func NormalizeOpenAIReasoning(body []byte) ([]byte, error)

NormalizeOpenAIReasoning accepts the common provider aliases used by OpenAI-compatible gateways and emits the shared inference codec's canonical reasoning_content field. It is deliberately scoped to string aliases used in Chat Completions responses; Responses API reasoning has its own codec.

func NormalizeOpenAIReasoningStream

func NormalizeOpenAIReasoningStream(response *http.Response) (*http.Response, error)

NormalizeOpenAIReasoningStream applies the same normalization lazily to SSE data frames, preserving streaming instead of buffering the provider response.

func UnsupportedCounter

func UnsupportedCounter(provider llm.Provider, apiFormat model.APIFormat) (contextcount.ContextCounter, error)

UnsupportedCounter returns the explicit exact-counter boundary shared by providers that document no matching token-count endpoint.

Types

type Config

type Config struct {
	Authenticator     auth.Authenticator
	Headers           http.Header
	Path              string
	PatchHeaders      func(inference.Request, http.Header)
	PatchRequest      func(map[string]json.RawMessage) error
	NormalizeResponse func([]byte) ([]byte, error)
	NormalizeStream   func(*http.Response) (*http.Response, error)
}

Config customizes one compatibility-backed provider client. Provider packages should construct this value from their public options rather than exposing it directly as their own public API.

func (Config) Clone

func (c Config) Clone() Config

Clone returns an independent configuration copy. Header and body-patch state are copied so a caller cannot mutate a live client through an option value.

type Definition

type Definition struct {
	Provider          llm.Provider
	DefaultBaseURL    string
	DefaultPath       string
	Authentication    auth.AuthKind
	KeyHeader         string
	Authenticator     func(auth.APIKey) (auth.Authenticator, error)
	PatchHeaders      func(inference.Request, http.Header)
	NormalizeResponse func([]byte) ([]byte, error)
	NormalizeStream   func(*http.Response) (*http.Response, error)
}

Definition contains immutable wire and policy facts for one simple provider. It is intentionally assembled by a public provider package, never discovered from an arbitrary model string.

type MissingAuthenticatorError

type MissingAuthenticatorError struct{}

MissingAuthenticatorError reports a provider construction bug before any transport is created. Passing auth.None() is the explicit no-auth choice.

func (*MissingAuthenticatorError) Error

func (e *MissingAuthenticatorError) Error() string

type Option

type Option func(*ProviderOptions)

Option customizes ProviderOptions.

func WithBodyField

func WithBodyField(name string, value any) Option

WithBodyField adds one JSON body field. The value is marshaled when the option is applied; unsupported values are retained as an option error and returned by NewProvider before any client is built.

func WithBodyPatch

func WithBodyPatch(patch func(map[string]json.RawMessage) error) Option

WithBodyPatch applies a provider-local patch after common fields are merged.

func WithHeader

func WithHeader(name, value string) Option

WithHeader adds one documented static request header.

func WithPath

func WithPath(path string) Option

WithPath overrides the documented provider route. It is intended for gateway packages whose upstream API has a stable proxy prefix.

type ProviderOptions

type ProviderOptions struct {
	Headers      http.Header
	Path         string
	BodyFields   map[string]json.RawMessage
	PatchRequest func(map[string]json.RawMessage) error
	// contains filtered or unexported fields
}

ProviderOptions is the common option state accepted by simple provider packages. Provider-specific packages expose only the option functions that their official documentation supports.

type UnsupportedAuthenticationError

type UnsupportedAuthenticationError struct {
	Provider llm.Provider
	Kind     auth.AuthKind
}

UnsupportedAuthenticationError is returned when a simple provider wrapper is accidentally used for an OAuth, GCP, service-key, or account-token flow.

func (*UnsupportedAuthenticationError) Error

Jump to

Keyboard shortcuts

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