Documentation
¶
Overview ¶
Package mladapter adapts res/int/model (low-level tensor inference) into res/int/inference (high-level generation, embeddings, transcription, synthesis).
res/int/model owns raw tensor inference through a caller-selected provider. res/int/inference owns the portable, transport-free inference contract. This package bridges them: it wraps an ml.Provider as an inference.Provider, applying explicit preprocessing and postprocessing for each operation.
Raw tensor inference must not pretend automatically to be text generation or content interpretation. Each operation requires an explicit preprocessor (request → tensors) and postprocessor (tensors → response).
Package mladapter adapts res/int/model (low-level tensor inference) into res/int/inference (high-level generation, embeddings, transcription, synthesis).
Index ¶
- type MLProvider
- func (a *MLProvider) BindEmbed(ref ml.Reference, pre Preprocessor[inference.EmbeddingRequest], ...)
- func (a *MLProvider) BindGenerate(ref ml.Reference, pre Preprocessor[inference.GenerationRequest], ...)
- func (a *MLProvider) BindSynthesize(ref ml.Reference, pre Preprocessor[inference.SpeechRequest], ...)
- func (a *MLProvider) BindTranscribe(ref ml.Reference, pre Preprocessor[inference.TranscriptionRequest], ...)
- func (a *MLProvider) Close() error
- func (a *MLProvider) Embed(ctx context.Context, req inference.EmbeddingRequest) (inference.EmbeddingResponse, error)
- func (a *MLProvider) Generate(ctx context.Context, req inference.GenerationRequest) (inference.GenerationResponse, error)
- func (a *MLProvider) Info(ctx context.Context) (inference.ProviderInfo, error)
- func (a *MLProvider) Models(ctx context.Context) ([]inference.ModelInfo, error)
- func (a *MLProvider) Stream(ctx context.Context, req inference.GenerationRequest, sink inference.EventSink) (inference.GenerationResponse, error)
- func (a *MLProvider) Synthesize(ctx context.Context, req inference.SpeechRequest) (inference.SpeechStream, error)
- func (a *MLProvider) Transcribe(ctx context.Context, req inference.TranscriptionRequest) (inference.TranscriptionResponse, error)
- type Postprocessor
- type Preprocessor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MLProvider ¶
type MLProvider struct {
// contains filtered or unexported fields
}
MLProvider wraps an ml.Provider as an inference.Provider. Each supported operation is bound to a model reference and a pair of pre/post processors. Operations that are not bound return inference.ErrUnsupported.
The wrapped ml.Provider and ml.Store are owned by the caller. Close only releases sessions created by this adapter.
func NewMLProvider ¶
func NewMLProvider(store *ml.Store, p ml.Provider, info inference.ProviderInfo) *MLProvider
NewMLProvider wraps p as an inference.Provider backed by store for model resolution. info is the provider metadata reported by Info. No operations are supported until BindGenerate, BindEmbed, BindTranscribe, or BindSynthesize is called.
func (*MLProvider) BindEmbed ¶
func (a *MLProvider) BindEmbed(ref ml.Reference, pre Preprocessor[inference.EmbeddingRequest], post Postprocessor[inference.EmbeddingResponse])
BindEmbed binds the Embed operation to an ml model.
func (*MLProvider) BindGenerate ¶
func (a *MLProvider) BindGenerate(ref ml.Reference, pre Preprocessor[inference.GenerationRequest], post Postprocessor[inference.GenerationResponse])
BindGenerate binds the Generate operation to an ml model. pre converts a GenerationRequest into ml tensors; post converts output tensors into a GenerationResponse.
func (*MLProvider) BindSynthesize ¶
func (a *MLProvider) BindSynthesize(ref ml.Reference, pre Preprocessor[inference.SpeechRequest], post Postprocessor[inference.SpeechStream])
BindSynthesize binds the Synthesize operation to an ml model. Synthesis produces a stream of audio bytes.
func (*MLProvider) BindTranscribe ¶
func (a *MLProvider) BindTranscribe(ref ml.Reference, pre Preprocessor[inference.TranscriptionRequest], post Postprocessor[inference.TranscriptionResponse])
BindTranscribe binds the Transcribe operation to an ml model.
func (*MLProvider) Close ¶
func (a *MLProvider) Close() error
Close releases all sessions owned by this adapter. It does not close the wrapped ml.Provider or ml.Store (the caller owns them).
func (*MLProvider) Embed ¶
func (a *MLProvider) Embed(ctx context.Context, req inference.EmbeddingRequest) (inference.EmbeddingResponse, error)
Embed returns embeddings for the inputs through the bound ml model.
func (*MLProvider) Generate ¶
func (a *MLProvider) Generate(ctx context.Context, req inference.GenerationRequest) (inference.GenerationResponse, error)
Generate runs one generation pass through the bound ml model.
func (*MLProvider) Info ¶
func (a *MLProvider) Info(ctx context.Context) (inference.ProviderInfo, error)
Info returns provider metadata.
func (*MLProvider) Models ¶
Models is not supported by raw ml provider metadata. Use ModelLister only via a remote provider adapter that supports model listing.
func (*MLProvider) Stream ¶
func (a *MLProvider) Stream(ctx context.Context, req inference.GenerationRequest, sink inference.EventSink) (inference.GenerationResponse, error)
Stream is not supported by raw ml tensor inference. Use Streamer only via a remote provider adapter that supports streaming.
func (*MLProvider) Synthesize ¶
func (a *MLProvider) Synthesize(ctx context.Context, req inference.SpeechRequest) (inference.SpeechStream, error)
Synthesize synthesizes text to audio through the bound ml model.
func (*MLProvider) Transcribe ¶
func (a *MLProvider) Transcribe(ctx context.Context, req inference.TranscriptionRequest) (inference.TranscriptionResponse, error)
Transcribe transcribes audio through the bound ml model.
type Postprocessor ¶
type Postprocessor[Resp any] interface { Postprocess(ctx context.Context, outputs []ml.Tensor) (Resp, error) }
Postprocessor converts res/int/model output tensors into a res/int/inference response. The implementation is responsible for model-specific decoding (detokenization, embedding normalization, etc.) and must honor ctx for cancellation.
func FuncPostprocessor ¶
func FuncPostprocessor[Resp any](fn func(context.Context, []ml.Tensor) (Resp, error)) Postprocessor[Resp]
FuncPostprocessor builds a Postprocessor from a function.
type Preprocessor ¶
type Preprocessor[Req any] interface { Preprocess(ctx context.Context, req Req) ([]ml.Tensor, error) }
Preprocessor converts a res/int/inference request into res/int/model tensors. The implementation is responsible for model-specific encoding (tokenization, feature extraction, etc.) and must honor ctx for cancellation.
func FuncPreprocessor ¶
func FuncPreprocessor[Req any](fn func(context.Context, Req) ([]ml.Tensor, error)) Preprocessor[Req]
FuncPreprocessor builds a Preprocessor from a function.