adapters

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTextGenerationUnsupported = fmt.Errorf("text generation not supported by this vendor")

ErrTextGenerationUnsupported marks a judgment-only vendor asked to write text. The capability filter keeps these models out of text chains; this is the backstop for a registry that says otherwise.

Functions

This section is empty.

Types

type AnthropicAdapter

type AnthropicAdapter struct {
	// contains filtered or unexported fields
}

func NewAnthropicAdapter

func NewAnthropicAdapter(client *anthropic.Client, model string, throttle *llm.ThrottleControl) *AnthropicAdapter

func (*AnthropicAdapter) GenerateText

func (a *AnthropicAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)

func (*AnthropicAdapter) GenerateTextStream

func (a *AnthropicAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, onChunk func(llm.StreamChunk) error) error

GenerateTextStream implements llm.StreamAdapter for Anthropic.

func (*AnthropicAdapter) SetPromptCache added in v1.0.0

func (a *AnthropicAdapter) SetPromptCache(on bool)

SetPromptCache marks cacheable prefixes, which repeat calls read at 0.1x input. Each new prefix is written at 1.25x, which pays off only when instructions repeat; hence opt-in per model.

func (*AnthropicAdapter) SetSoftSchema

func (a *AnthropicAdapter) SetSoftSchema(soft bool)

SetSoftSchema switches this adapter to prompt-described schemas.

type BedrockAdapter

type BedrockAdapter struct {
	// contains filtered or unexported fields
}

func NewBedrockAdapter

func NewBedrockAdapter(client BedrockRuntimeClient, model string, throttle *llm.ThrottleControl) *BedrockAdapter

func (*BedrockAdapter) GenerateText

func (a *BedrockAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)

func (*BedrockAdapter) GenerateTextStream

func (a *BedrockAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, onChunk func(llm.StreamChunk) error) error

func (*BedrockAdapter) SetSoftSchema

func (a *BedrockAdapter) SetSoftSchema(soft bool)

SetSoftSchema switches this adapter to prompt-described schemas.

type BedrockRuntimeClient

type BedrockRuntimeClient interface {
	Converse(ctx context.Context, params *bedrockruntime.ConverseInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.ConverseOutput, error)
	ConverseStream(ctx context.Context, params *bedrockruntime.ConverseStreamInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.ConverseStreamOutput, error)
}

BedrockRuntimeClient abstracts the AWS Bedrock Runtime client for testing.

type GoogleAdapter

type GoogleAdapter struct {
	// contains filtered or unexported fields
}

func NewGoogleAdapter

func NewGoogleAdapter(geminiClient *genai.Client, model string, throttle *llm.ThrottleControl) *GoogleAdapter

func (*GoogleAdapter) CancelBatch

func (a *GoogleAdapter) CancelBatch(ctx context.Context, vendorJobID string) error

CancelBatch requests cancellation of the batch job at the vendor.

func (*GoogleAdapter) CreateEmbeddings

func (a *GoogleAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, meta map[string]string) (*llm.EmbeddingResult, error)

CreateEmbeddings implements llm.EmbeddingAdapter for Google Gemini models.

func (*GoogleAdapter) FetchBatchResults

func (a *GoogleAdapter) FetchBatchResults(ctx context.Context, vendorJobID string, items []*llm.BatchSubmitItem) ([]*llm.BatchItemResult, error)

FetchBatchResults retrieves results from either inlined responses or output file download.

func (*GoogleAdapter) GenerateImage

func (a *GoogleAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)

GenerateImage renders one image from a text prompt via Gemini's native image modality. Like TTS, the image model is its own setting, not a chat tier.

func (*GoogleAdapter) GenerateText

func (a *GoogleAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)

func (*GoogleAdapter) GenerateTextStream

func (a *GoogleAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, onChunk func(llm.StreamChunk) error) error

GenerateTextStream implements llm.StreamAdapter for Google Gemini.

func (*GoogleAdapter) GetBatch

func (a *GoogleAdapter) GetBatch(ctx context.Context, vendorJobID string) (*llm.BatchJobStatus, error)

GetBatch polls the vendor for the batch job state.

func (*GoogleAdapter) SetImageModel

func (a *GoogleAdapter) SetImageModel(model string)

SetImageModel overrides the native image model used by GenerateImage. Empty keeps the default.

func (*GoogleAdapter) SetSoftSchema

func (a *GoogleAdapter) SetSoftSchema(s bool)

func (*GoogleAdapter) SetTTS

func (a *GoogleAdapter) SetTTS(model, voice string)

SetTTS overrides the text-to-speech model and voice used by SynthesizeSpeech. Empty values keep the defaults.

func (*GoogleAdapter) SubmitBatch

func (a *GoogleAdapter) SubmitBatch(ctx context.Context, batchID string, items []*llm.BatchSubmitItem) (string, error)

SubmitBatch submits a batch of text generation requests to the Gemini Batch API. Batches up to ~15 MB are sent as InlinedRequests; larger ones are uploaded as a JSONL file.

func (*GoogleAdapter) SynthesizeSpeech

func (a *GoogleAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)

SynthesizeSpeech generates OGG/Opus audio for a short phrase. Gemini returns raw PCM, which is transcoded to OGG/Opus via ffmpeg (must be on PATH).

type OpenAIAdapter

type OpenAIAdapter struct {
	// contains filtered or unexported fields
}

func NewOpenAIAdapter

func NewOpenAIAdapter(client *openai.Client, model string, throttle *llm.ThrottleControl) *OpenAIAdapter

func (*OpenAIAdapter) CreateEmbeddings

func (a *OpenAIAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, meta map[string]string) (*llm.EmbeddingResult, error)

CreateEmbeddings implements llm.EmbeddingAdapter for OpenAI and OpenAI-compatible vendors.

func (*OpenAIAdapter) EvaluateRollouts

EvaluateRollouts scores multiple rollout candidate actions against state and criteria. Calls the /v1/decisions/rollouts endpoint, yielding ErrJudgmentUnsupported if not supported.

func (*OpenAIAdapter) GenerateImage

func (a *OpenAIAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)

GenerateImage renders one landscape image from a text prompt. The GPT image models always answer base64, never a URL.

func (*OpenAIAdapter) GenerateText

func (a *OpenAIAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)

func (*OpenAIAdapter) GenerateTextStream

func (a *OpenAIAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, onChunk func(llm.StreamChunk) error) error

GenerateTextStream implements llm.StreamAdapter for OpenAI.

func (*OpenAIAdapter) Judge

func (a *OpenAIAdapter) Judge(ctx context.Context, req *llm.JudgeRequest, _ string, _ map[string]string) (*llm.JudgeResult, error)

Judge calls OpenAI's /v1/decisions endpoint. Answers typed questions about state in a single pass, returning probabilities without prose generation.

func (*OpenAIAdapter) SetDecisionsConfig

func (a *OpenAIAdapter) SetDecisionsConfig(endpoint, apiKey string)

SetDecisionsConfig configures endpoint and apiKey for OpenAI Decisions API calls.

func (*OpenAIAdapter) SetHTTPClient

func (a *OpenAIAdapter) SetHTTPClient(client *http.Client)

SetHTTPClient overrides the HTTP client for REST calls like the Decisions API.

func (*OpenAIAdapter) SetImageModel

func (a *OpenAIAdapter) SetImageModel(model string)

SetImageModel overrides the model used by GenerateImage. Empty keeps the default.

func (*OpenAIAdapter) SetSoftSchema

func (a *OpenAIAdapter) SetSoftSchema(soft bool)

SetSoftSchema switches this adapter to prompt-described schemas.

func (*OpenAIAdapter) SetTTS

func (a *OpenAIAdapter) SetTTS(model, voice string)

SetTTS overrides the text-to-speech model and voice used by SynthesizeSpeech. Empty values keep the defaults.

func (*OpenAIAdapter) SetThinkingOff

func (a *OpenAIAdapter) SetThinkingOff(fields map[string]any)

SetThinkingOff sets the request fields that turn the vendor's default reasoning off.

func (*OpenAIAdapter) SynthesizeSpeech

func (a *OpenAIAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)

SynthesizeSpeech generates OGG/Opus audio for a short phrase. OpenAI returns the Opus container directly, so no ffmpeg transcode is needed.

type OpenAIDecisionError

type OpenAIDecisionError struct {
	Status int
	Body   string
}

OpenAIDecisionError is a non-2xx response from OpenAI's Decisions API. Implements HTTPStatusError so the router retries 429 and 5xx across fallback models.

func (*OpenAIDecisionError) Error

func (e *OpenAIDecisionError) Error() string

func (*OpenAIDecisionError) HTTPStatus

func (e *OpenAIDecisionError) HTTPStatus() int

type Pricer

type Pricer func(usage llm.TokensUsage, startedAt time.Time) int64

Pricer prices one call's usage in nano-USD for a call that started at the given time (rates can depend on the hour).

type TrackingAdapter

type TrackingAdapter struct {
	// contains filtered or unexported fields
}

TrackingAdapter wraps a ClientAdapter and automatically tracks usage

func NewTrackingAdapter

func NewTrackingAdapter(adapter llm.ClientAdapter, tracker llm.UsageTracker, vendor, model string) *TrackingAdapter

NewTrackingAdapter creates a new tracking adapter that wraps an existing adapter

func (*TrackingAdapter) CancelBatch

func (t *TrackingAdapter) CancelBatch(ctx context.Context, vendorJobID string) error

CancelBatch delegates to the wrapped adapter if it implements BatchAdapter.

func (*TrackingAdapter) CreateEmbeddings

func (t *TrackingAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, meta map[string]string) (*llm.EmbeddingResult, error)

CreateEmbeddings forwards to the wrapped adapter's optional embedding capability and tracks usage. Adapters without one surface ErrEmbeddingUnsupported.

func (*TrackingAdapter) EvaluateRollouts

func (t *TrackingAdapter) EvaluateRollouts(ctx context.Context, req *llm.EvaluateRolloutsRequest, userID string, meta map[string]string) (*llm.EvaluateRolloutsResult, error)

EvaluateRollouts forwards to the wrapped adapter's optional rollout judgment capability and tracks usage. Adapters without one surface ErrJudgmentUnsupported.

func (*TrackingAdapter) FetchBatchResults

func (t *TrackingAdapter) FetchBatchResults(ctx context.Context, vendorJobID string, items []*llm.BatchSubmitItem) ([]*llm.BatchItemResult, error)

FetchBatchResults delegates to the wrapped adapter if it implements BatchAdapter.

func (*TrackingAdapter) GenerateImage

func (t *TrackingAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)

GenerateImage forwards to the wrapped adapter's optional image capability and tracks usage. Adapters without one surface ErrImageGenerationUnsupported.

func (*TrackingAdapter) GenerateText

func (t *TrackingAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)

GenerateText generates text and tracks usage

func (*TrackingAdapter) GenerateTextStream

func (t *TrackingAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, onChunk func(llm.StreamChunk) error) error

GenerateTextStream forwards streaming text generation and tracks usage upon completion.

func (*TrackingAdapter) GetBatch

func (t *TrackingAdapter) GetBatch(ctx context.Context, vendorJobID string) (*llm.BatchJobStatus, error)

GetBatch delegates to the wrapped adapter if it implements BatchAdapter.

func (*TrackingAdapter) Judge

func (t *TrackingAdapter) Judge(ctx context.Context, req *llm.JudgeRequest, userID string, meta map[string]string) (*llm.JudgeResult, error)

Judge forwards to the wrapped adapter's optional judgment capability and tracks usage. Adapters without one surface ErrJudgmentUnsupported.

func (*TrackingAdapter) SubmitBatch

func (t *TrackingAdapter) SubmitBatch(ctx context.Context, batchID string, items []*llm.BatchSubmitItem) (string, error)

SubmitBatch delegates to the wrapped adapter if it implements BatchAdapter.

func (*TrackingAdapter) SupportsStreaming

func (t *TrackingAdapter) SupportsStreaming() bool

SupportsStreaming reports whether the underlying adapter supports streaming.

func (*TrackingAdapter) SynthesizeSpeech

func (t *TrackingAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)

SynthesizeSpeech synthesizes speech and tracks usage

func (*TrackingAdapter) Unwrap

func (t *TrackingAdapter) Unwrap() llm.ClientAdapter

Unwrap returns the wrapped adapter.

func (*TrackingAdapter) WithPricer

func (t *TrackingAdapter) WithPricer(p Pricer) *TrackingAdapter

WithPricer stamps every usage event with its cost; without one events carry 0.

type TypeSafeAdapter

type TypeSafeAdapter struct {
	// contains filtered or unexported fields
}

TypeSafeAdapter talks to TypeSafe's System One API. It is judgment-only: the vendor writes no text, so GenerateText is refused rather than faked.

func NewTypeSafeAdapter

func NewTypeSafeAdapter(endpoint, apiKey, model string) *TypeSafeAdapter

func (*TypeSafeAdapter) GenerateText

func (*TypeSafeAdapter) Judge

Judge asks every question against one state in a single call. userID and meta are accepted for interface symmetry: the vendor takes neither, and the tracking adapter is what records them.

type TypeSafeError

type TypeSafeError struct {
	Status int
	Body   string
}

TypeSafeError is a non-2xx reply. The status drives retryability; the body is kept short and never logged for 401, where it may echo the credential.

func (*TypeSafeError) Error

func (e *TypeSafeError) Error() string

func (*TypeSafeError) HTTPStatus

func (e *TypeSafeError) HTTPStatus() int

HTTPStatus makes 429 and 5xx (including the vendor's 529 overloaded) retryable through llm.IsRetryableError, leaving 401 and 422 terminal.

Jump to

Keyboard shortcuts

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