Documentation
¶
Overview ¶
Package inference bridges the portable src/ctn/contract/inference contract with the Ext plugin engine. It declares the inference.provider/v1 plugin contract and supplies host and guest helpers so any src/ctn/contract/inference Provider can be served as an Ext plugin guest and invoked by a host through a plugin session.
The package depends only on src/ctn/contract/inference (the contract) and pkg/ext-go/engine/plugin (the plugin mechanics). It knows nothing about CTN command dispatch or any concrete provider.
Package inference guest-side helpers register a src/ctn/contract/inference.Provider as an Ext plugin guest serving inference.provider/v1.
Package inference host-side helpers call inference.provider/v1 operations through a plugin session.
Package inference guest-side operation declarations for inference.provider/v1.
Package inference guest-side stream bridging for the stream and synthesize operations, which open ext.stream instances.
Index ¶
- Constants
- Variables
- func CapabilityOperation(c inference.Capability) (string, bool)
- func DecodeAudio(item json.RawMessage) ([]byte, error)
- func DecodeEvent(item json.RawMessage) (inference.GenerationEvent, error)
- func DecodeStructuredOutput[T any](response domain.GenerationResponse, schema json.RawMessage) (T, error)
- func Descriptor(id plugin.Identity) plugin.Descriptor
- func Operations() []plugin.Operation
- func PackageExecutable(options ExecutablePackage) (packagekit.Manifest, error)
- func RegisterProvider(r *author.Registry, p inference.Provider, ...) (*plugin.Descriptor, error)
- func ServeCurrentExecutable(ctx context.Context, id, version string, provider inference.Provider, ...) error
- func ServeStdio(ctx context.Context, id plugin.Identity, provider inference.Provider, ...) error
- func ValidateStructuredOutput(response domain.GenerationResponse, schema json.RawMessage) error
- type Backend
- type Client
- func (c *Client) Capabilities(ctx context.Context) (inference.ProviderInfo, error)
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Embed(ctx context.Context, req inference.EmbeddingRequest) (inference.EmbeddingResponse, error)
- func (c *Client) Generate(ctx context.Context, req inference.GenerationRequest) (inference.GenerationResponse, error)
- func (c *Client) Health(ctx context.Context) (health, error)
- func (c *Client) Models(ctx context.Context) ([]inference.ModelInfo, error)
- func (c *Client) Stream(ctx context.Context, req inference.GenerationRequest) (*stream.Client, error)
- func (c *Client) Synthesize(ctx context.Context, req inference.SpeechRequest) (*stream.Client, error)
- func (c *Client) Transcribe(ctx context.Context, req inference.TranscriptionRequest) (inference.TranscriptionResponse, error)
- type DescriptorType
- type ExecutablePackage
- type Identity
- type Options
- type Provider
- type Request
- type Session
Constants ¶
const ( OpCapabilities = "capabilities" // observation OpHealth = "health" // observation OpGenerate = "generate" // action OpStream = "stream" // action (opens an ext.stream of GenerationEvent) OpEmbed = "embed" // action OpTranscribe = "transcribe" // action OpSynthesize = "synthesize" // action (opens an ext.stream of audio bytes) OpModels = "models" // observation OpClose = "close" // action )
Operation names for the inference.provider/v1 contract. Surfaces are admission classifications with no built-in authority.
const ContractName = "inference.provider"
ContractName is the recorded plugin contract name (see docs/contract-names.md).
const ContractVersion = "v1"
ContractVersion is the contract version.
Variables ¶
var ContractRef = plugin.ContractRef{Name: ContractName, Version: ContractVersion}
ContractRef is the exact contract reference for inference.provider/v1.
Functions ¶
func CapabilityOperation ¶
func CapabilityOperation(c inference.Capability) (string, bool)
CapabilityOperation maps a src/ctn/contract/inference capability to its contract operation. A provider that does not advertise a capability must return ErrUnsupported for that operation.
func DecodeAudio ¶
func DecodeAudio(item json.RawMessage) ([]byte, error)
DecodeAudio decodes one item of a synthesis stream opened by Client.Synthesize into the audio bytes it carries.
func DecodeEvent ¶
func DecodeEvent(item json.RawMessage) (inference.GenerationEvent, error)
DecodeEvent decodes one item of a generation stream opened by Client.Stream. The last event of a stream that ends without error is a completed event carrying the response.
func DecodeStructuredOutput ¶
func DecodeStructuredOutput[T any](response domain.GenerationResponse, schema json.RawMessage) (T, error)
func Descriptor ¶
func Descriptor(id plugin.Identity) plugin.Descriptor
Descriptor builds the plugin Descriptor for an inference provider plugin given its identity. The provider advertises exactly the operations it supports through src/ctn/contract/inference.ProviderInfo.Capabilities; the descriptor declares the complete contract surface and the guest enforces support at call time.
func Operations ¶
Operations returns the full declared operation set for the contract, with surfaces. Stream and synthesize declare progress because they may emit stream frames before completion.
func PackageExecutable ¶
func PackageExecutable(options ExecutablePackage) (packagekit.Manifest, error)
PackageExecutable copies a compiled guest into a sealed ext.io/v1 directory. The caller reviews and installs the resulting package separately.
func RegisterProvider ¶
func RegisterProvider(r *author.Registry, p inference.Provider, authorize func(context.Context, plugin.Request) error) (*plugin.Descriptor, error)
RegisterProvider registers all inference.provider/v1 operations on the author registry and returns the plugin Descriptor. The authorize callback is required by the engine and must enforce the host's policy. RegisterProvider creates an internal ext.stream service for stream and synthesize operations.
func ServeCurrentExecutable ¶
func ServeCurrentExecutable(ctx context.Context, id, version string, provider inference.Provider, authorize func(context.Context, plugin.Request) error) error
ServeCurrentExecutable pins the guest identity to the running executable.
func ServeStdio ¶
func ServeStdio(ctx context.Context, id plugin.Identity, provider inference.Provider, authorize func(context.Context, plugin.Request) error) error
ServeStdio serves one caller-configured provider over the Ext JSON-line transport. The caller supplies the reviewed identity and admission policy.
func ValidateStructuredOutput ¶
func ValidateStructuredOutput(response domain.GenerationResponse, schema json.RawMessage) error
ValidateStructuredOutput validates completed model output with the Ext engine's bounded, offline JSON Schema implementation.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls inference.provider/v1 operations on a plugin session.
func (*Client) Capabilities ¶
Capabilities returns the provider's metadata.
func (*Client) Embed ¶
func (c *Client) Embed(ctx context.Context, req inference.EmbeddingRequest) (inference.EmbeddingResponse, error)
Embed returns embeddings for the inputs.
func (*Client) Generate ¶
func (c *Client) Generate(ctx context.Context, req inference.GenerationRequest) (inference.GenerationResponse, error)
Generate runs one generation pass and returns the complete response.
func (*Client) Stream ¶
func (c *Client) Stream(ctx context.Context, req inference.GenerationRequest) (*stream.Client, error)
Stream opens an ext.stream of GenerationEvent and returns its reader. The returned stream.Client reads from the provider's generation stream via the ext.stream protocol; DecodeEvent decodes each item. A stream that ends without error ends with a completed event carrying the final GenerationResponse.
func (*Client) Synthesize ¶
func (c *Client) Synthesize(ctx context.Context, req inference.SpeechRequest) (*stream.Client, error)
Synthesize opens an ext.stream of audio and returns its reader; DecodeAudio turns each item back into bytes.
func (*Client) Transcribe ¶
func (c *Client) Transcribe(ctx context.Context, req inference.TranscriptionRequest) (inference.TranscriptionResponse, error)
Transcribe transcribes audio.
type DescriptorType ¶
type DescriptorType = plugin.Descriptor
type ExecutablePackage ¶
type ExecutablePackage struct {
ID, Version, Binary, OutputDir, OS, Arch string
}
ExecutablePackage describes one compiled inference guest to package. Empty OS and Arch use the current platform. The output directory must not exist.
type Identity ¶
Host and guest construction types are re-exported here so inference programs depend on the integration module instead of importing the engine directly.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider adapts a src/ctn/contract/inference.Provider to the plugin guest contract. The guest declares the full inference.provider/v1 surface and routes each operation to the provider. A provider returns inference.ErrUnsupported for any operation it does not advertise.