Documentation
¶
Overview ¶
Package inference provides a single, normalized interface for getting language model completions from multiple providers.
The main entry point is ProviderSetAPI, which lets you:
- register one or more providers (Anthropic, OpenAI Chat Completions, OpenAI Responses, ...),
- configure and rotate API keys,
- send normalized completion requests and receive normalized outputs,
- optionally stream partial text / reasoning and capture HTTP‑level debug information.
Index ¶
- Constants
- Variables
- func ComputeDataContractHash() (string, error)
- func ValidateDataContract() error
- type AddProviderConfig
- type DataContractInfo
- type DebugClientBuilder
- type ProviderSetAPI
- func (ps *ProviderSetAPI) AddProvider(ctx context.Context, provider spec.ProviderName, config *AddProviderConfig) (spec.ProviderParam, error)
- func (ps *ProviderSetAPI) DeleteProvider(ctx context.Context, provider spec.ProviderName) error
- func (ps *ProviderSetAPI) FetchCompletion(ctx context.Context, provider spec.ProviderName, ...) (*spec.FetchCompletionResponse, error)
- func (ps *ProviderSetAPI) GetProviderCapability(ctx context.Context, provider spec.ProviderName) (spec.ModelCapabilities, error)
- func (ps *ProviderSetAPI) SetProviderAPIKey(ctx context.Context, provider spec.ProviderName, apiKey string) error
- type ProviderSetOption
- type SetProviderAPIKeyRequestBody
- type SetProviderAPIKeyResponse
Constants ¶
const DataContractHash = "sha256:40d4d92460554cc5959464baa982f4cb6178fe77639d6c6bc01c6e682a9bd1ee"
DataContractHash is a SHA-256 of the contents of DataContractFiles. It is validated by tests and can be used by downstream consumers to check that they are running against the contract version they were built for.
Format: "sha256:<hexstring>".
const DataContractVersion = "v1.0.0"
DataContractVersion is bumped when the *schema* of the contract types changes.
Variables ¶
var DataContractFiles = []string{
"spec/data_cache.go",
"spec/data_citation.go",
"spec/data_content.go",
"spec/data_error.go",
"spec/data_io_union.go",
"spec/data_model.go",
"spec/data_tool.go",
}
DataContractFiles lists files that define the data contract. Paths are relative to the repo root.
These files should only contain data-contract types (structs/enums) that downstream consumers rely on structurally. Any change to these files will change the contract hash. It does NOT contain api contracts.
Functions ¶
func ComputeDataContractHash ¶
ComputeDataContractHash recomputes the SHA-256 hash of the contract files' contents. It is intended for use in tests and development tooling.
NOTE: This function assumes it is run in a source checkout of the module where the paths in DataContractFiles exist on disk. It is not suitable for use in production binaries where the Go source tree might not be available.
func ValidateDataContract ¶
func ValidateDataContract() error
ValidateDataContract recomputes the hash and compares it to DataContractHash. Tests in this module should call this to enforce that any schema change in the contract files is accompanied by an explicit update of DataContractHash (and, if breaking, DataContractVersion).
Types ¶
type AddProviderConfig ¶
type DataContractInfo ¶
type DataContractInfo struct {
Version string `json:"version"`
Hash string `json:"hash"`
Files []string `json:"files"`
}
DataContractInfo is the public shape returned to callers who want to validate they are compatible with this version of the contract.
func GetDataContractInfo ¶
func GetDataContractInfo() DataContractInfo
GetDataContractInfo returns the current contract version/hash metadata.
type DebugClientBuilder ¶
type DebugClientBuilder func(p spec.ProviderParam) spec.CompletionDebugger
DebugClientBuilder constructs a CompletionDebugger for a given provider. A nil builder or a nil returned debugger disable debugging for that provider.
type ProviderSetAPI ¶
type ProviderSetAPI struct {
// contains filtered or unexported fields
}
func NewProviderSetAPI ¶
func NewProviderSetAPI( opts ...ProviderSetOption, ) (*ProviderSetAPI, error)
NewProviderSetAPI creates a new ProviderSet and installs the process-wide logger used by this SDK. The logger is chosen via WithLoggerBuilder; if no builder is provided or it returns nil, a no-op logger is used.
func (*ProviderSetAPI) AddProvider ¶
func (ps *ProviderSetAPI) AddProvider( ctx context.Context, provider spec.ProviderName, config *AddProviderConfig, ) (spec.ProviderParam, error)
func (*ProviderSetAPI) DeleteProvider ¶
func (ps *ProviderSetAPI) DeleteProvider( ctx context.Context, provider spec.ProviderName, ) error
func (*ProviderSetAPI) FetchCompletion ¶
func (ps *ProviderSetAPI) FetchCompletion( ctx context.Context, provider spec.ProviderName, fetchCompletionRequest *spec.FetchCompletionRequest, opts *spec.FetchCompletionOptions, ) (*spec.FetchCompletionResponse, error)
FetchCompletion processes a completion request for a given provider.
func (*ProviderSetAPI) GetProviderCapability ¶ added in v0.9.1
func (ps *ProviderSetAPI) GetProviderCapability( ctx context.Context, provider spec.ProviderName, ) (spec.ModelCapabilities, error)
func (*ProviderSetAPI) SetProviderAPIKey ¶
func (ps *ProviderSetAPI) SetProviderAPIKey( ctx context.Context, provider spec.ProviderName, apiKey string, ) error
SetProviderAPIKey sets the key for a given provider.
type ProviderSetOption ¶
type ProviderSetOption func(*ProviderSetAPI)
ProviderSetOption configures optional behavior for ProviderSetAPI.
func WithDebugClientBuilder ¶
func WithDebugClientBuilder(builder DebugClientBuilder) ProviderSetOption
WithDebugClientBuilder configures a CompletionDebugger factory. The builder is invoked once per provider when it is added. Returning nil disables debugging for that provider.
func WithLogger ¶
func WithLogger(logger *slog.Logger) ProviderSetOption
type SetProviderAPIKeyRequestBody ¶
type SetProviderAPIKeyRequestBody struct {
APIKey string `json:"apiKey" required:"true"`
}
type SetProviderAPIKeyResponse ¶
type SetProviderAPIKeyResponse struct{}
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
integration
Package integration contains example-style tests that demonstrate how to call the inference-go library against real providers.
|
Package integration contains example-style tests that demonstrate how to call the inference-go library against real providers. |