translation

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package translation serves surfaces a provider lacks by translating through llm-translate. Every conversion reports its losses. An Adapter checks them against a core.LossPolicy and returns all of them, including the losses the policy allows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Provider core.Provider
	Policy   core.LossPolicy
}

Adapter wraps a provider and serves, besides its native surfaces, every surface llm-translate can convert to one of them:

  • Messages over a Chat Completions provider, streaming included;
  • Chat Completions over a Responses provider;
  • Responses over a Chat Completions provider.

Losses the provider itself reports are merged into the same report. Request losses are checked before the provider is called, so a rejected translation never reaches it. Response losses of a stream are reported through core.LossReporter, not enforced, because their frames are already delivered.

func (Adapter) Invoke

func (a Adapter) Invoke(ctx context.Context, request core.Request) (core.Response, error)

Invoke serves request natively when the provider can, and otherwise by translation.

func (Adapter) ListModels

func (a Adapter) ListModels(ctx context.Context, credential *core.Credential) ([]core.ModelInfo, error)

ListModels delegates to the wrapped provider.

func (Adapter) NativeSurfaces

func (a Adapter) NativeSurfaces(model string) []core.ModelSurface

NativeSurfaces reports the wrapped provider's native surfaces: translated surfaces are, by definition, not native.

func (Adapter) Stream

func (a Adapter) Stream(ctx context.Context, request core.Request) (core.StreamIter, error)

Stream serves request natively when the provider can, and otherwise by translation on routes that stream. The returned stream implements core.LossReporter.

func (Adapter) Surfaces

func (a Adapter) Surfaces(model string) []core.ModelSurface

Surfaces lists every surface the adapter serves for model, native first.

func (Adapter) Unwrap added in v0.14.0

func (a Adapter) Unwrap() core.Provider

Unwrap returns the wrapped provider. The adapter hands it the requests of its native surfaces unchanged, so core.PreservesWire and core.CountTokens read the wrapped provider's declarations through the adapter.

type ChatTranscriptionAdapter added in v1.2.0

type ChatTranscriptionAdapter struct {
	Provider    core.Provider
	Enabled     func(model string) bool
	Instruction string
}

ChatTranscriptionAdapter serves the OpenAI audio_transcriptions surface by sending input_audio to a provider's native Chat Completions surface.

Enabled is mandatory and is evaluated for every model. A provider-level opt-in returns true for every model; a model-level opt-in names exact rows. No model-name inference is performed.

func (ChatTranscriptionAdapter) Invoke added in v1.2.0

func (ChatTranscriptionAdapter) ListModels added in v1.2.0

func (a ChatTranscriptionAdapter) ListModels(ctx context.Context, credential *core.Credential) ([]core.ModelInfo, error)

ListModels adds the translated transcription surface only to exact rows the caller opted in. Other catalog rows remain unchanged.

func (ChatTranscriptionAdapter) NativeSurfaces added in v1.2.0

func (a ChatTranscriptionAdapter) NativeSurfaces(model string) []core.ModelSurface

func (ChatTranscriptionAdapter) Stream added in v1.2.0

func (ChatTranscriptionAdapter) Surfaces added in v1.2.0

func (a ChatTranscriptionAdapter) Surfaces(model string) []core.ModelSurface

Surfaces reports translated transcription only for explicitly enabled models, after the wrapped provider's native surfaces.

func (ChatTranscriptionAdapter) Unwrap added in v1.2.0

Jump to

Keyboard shortcuts

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