Documentation
¶
Index ¶
- Variables
- type AnthropicAdapter
- func (a *AnthropicAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)
- func (a *AnthropicAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, ...) error
- func (a *AnthropicAdapter) SetPromptCache(on bool)
- func (a *AnthropicAdapter) SetSoftSchema(soft bool)
- type BedrockAdapter
- type BedrockRuntimeClient
- type GoogleAdapter
- func (a *GoogleAdapter) CancelBatch(ctx context.Context, vendorJobID string) error
- func (a *GoogleAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, ...) (*llm.EmbeddingResult, error)
- func (a *GoogleAdapter) FetchBatchResults(ctx context.Context, vendorJobID string, items []*llm.BatchSubmitItem) ([]*llm.BatchItemResult, error)
- func (a *GoogleAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)
- func (a *GoogleAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)
- func (a *GoogleAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, ...) error
- func (a *GoogleAdapter) GetBatch(ctx context.Context, vendorJobID string) (*llm.BatchJobStatus, error)
- func (a *GoogleAdapter) SetImageModel(model string)
- func (a *GoogleAdapter) SetSoftSchema(s bool)
- func (a *GoogleAdapter) SetTTS(model, voice string)
- func (a *GoogleAdapter) SubmitBatch(ctx context.Context, batchID string, items []*llm.BatchSubmitItem) (string, error)
- func (a *GoogleAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)
- type OpenAIAdapter
- func (a *OpenAIAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, ...) (*llm.EmbeddingResult, error)
- func (a *OpenAIAdapter) EvaluateRollouts(ctx context.Context, req *llm.EvaluateRolloutsRequest, _ string, ...) (*llm.EvaluateRolloutsResult, error)
- func (a *OpenAIAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)
- func (a *OpenAIAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)
- func (a *OpenAIAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, ...) error
- func (a *OpenAIAdapter) Judge(ctx context.Context, req *llm.JudgeRequest, _ string, _ map[string]string) (*llm.JudgeResult, error)
- func (a *OpenAIAdapter) SetDecisionsConfig(endpoint, apiKey string)
- func (a *OpenAIAdapter) SetHTTPClient(client *http.Client)
- func (a *OpenAIAdapter) SetImageModel(model string)
- func (a *OpenAIAdapter) SetSoftSchema(soft bool)
- func (a *OpenAIAdapter) SetTTS(model, voice string)
- func (a *OpenAIAdapter) SetThinkingOff(fields map[string]any)
- func (a *OpenAIAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)
- type OpenAIDecisionError
- type Pricer
- type TrackingAdapter
- func (t *TrackingAdapter) CancelBatch(ctx context.Context, vendorJobID string) error
- func (t *TrackingAdapter) CreateEmbeddings(ctx context.Context, req *llm.EmbeddingRequest, userID string, ...) (*llm.EmbeddingResult, error)
- func (t *TrackingAdapter) EvaluateRollouts(ctx context.Context, req *llm.EvaluateRolloutsRequest, userID string, ...) (*llm.EvaluateRolloutsResult, error)
- func (t *TrackingAdapter) FetchBatchResults(ctx context.Context, vendorJobID string, items []*llm.BatchSubmitItem) ([]*llm.BatchItemResult, error)
- func (t *TrackingAdapter) GenerateImage(ctx context.Context, prompt, userID string, meta map[string]string) (*llm.ImageResult, error)
- func (t *TrackingAdapter) GenerateText(ctx context.Context, chat *llm.ChatContext) (*llm.Response, error)
- func (t *TrackingAdapter) GenerateTextStream(ctx context.Context, chat *llm.ChatContext, ...) error
- func (t *TrackingAdapter) GetBatch(ctx context.Context, vendorJobID string) (*llm.BatchJobStatus, error)
- func (t *TrackingAdapter) Judge(ctx context.Context, req *llm.JudgeRequest, userID string, ...) (*llm.JudgeResult, error)
- func (t *TrackingAdapter) SubmitBatch(ctx context.Context, batchID string, items []*llm.BatchSubmitItem) (string, error)
- func (t *TrackingAdapter) SupportsStreaming() bool
- func (t *TrackingAdapter) SynthesizeSpeech(ctx context.Context, text, language, userID string, meta map[string]string) (*llm.SpeechResult, error)
- func (t *TrackingAdapter) Unwrap() llm.ClientAdapter
- func (t *TrackingAdapter) WithPricer(p Pricer) *TrackingAdapter
- type TypeSafeAdapter
- type TypeSafeError
Constants ¶
This section is empty.
Variables ¶
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 ¶
func (a *OpenAIAdapter) EvaluateRollouts(ctx context.Context, req *llm.EvaluateRolloutsRequest, _ string, _ map[string]string) (*llm.EvaluateRolloutsResult, error)
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 ¶
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 (a *TypeSafeAdapter) GenerateText(context.Context, *llm.ChatContext) (*llm.Response, error)
func (*TypeSafeAdapter) Judge ¶
func (a *TypeSafeAdapter) Judge(ctx context.Context, req *llm.JudgeRequest, _ string, _ map[string]string) (*llm.JudgeResult, error)
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 ¶
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.