Documentation
¶
Overview ¶
Package provider defines the interface for LLM providers.
Index ¶
- Variables
- func BuildJSONInstruction(prompt string, schema json.RawMessage) string
- func InjectJSONInstruction(messages []message.Message, schema json.RawMessage) []message.Message
- func MapReasoning(effort string, values map[string]string) (string, []stream.Warning)
- func OpenAIReasoning(effort, explicit string) (string, []stream.Warning)
- func ParseProviderOptions[T any](m map[string]any) (*T, error)
- func ReasoningBudget(effort string, limit int) (int, []stream.Warning)
- func ValidateInlineOrURLFile(file message.FilePart, mimes []string, allowURL bool) error
- func ValidateMessageContent(messages []message.Message, validator FileValidator, siblingText bool, ...) error
- func ValidateMessageFiles(messages []message.Message, validator FileValidator) error
- func ValidatePromptMessages(messages []message.Message) error
- func ValidateTextToolMessages(messages []message.Message) error
- type Capabilities
- type EmbeddingProvider
- type FileValidationFunc
- type FileValidator
- type FilesProvider
- type ImageProvider
- type LanguageProvider
- type MessageValidator
- type ModelInfo
- type Options
- type Provider
- type Registry
- type RerankingProvider
- type SpeechProvider
- type StreamInput
- type TranscriptionProvider
Constants ¶
This section is empty.
Variables ¶
var ErrResponseFormatUnsupported = errors.New("provider does not support requested ResponseFormat")
ErrResponseFormatUnsupported is returned by a provider that cannot honor a requested stream.ResponseFormat. Wrap with fmt.Errorf("%w: details", ...) to add provider context. Callers match with errors.Is.
var ErrUnsupportedFile = errors.New("file representation is not supported by this adapter for this role and model")
ErrUnsupportedFile is intentionally independent of payload, MIME, URL and tool identity so it is safe to display or log.
Functions ¶
func BuildJSONInstruction ¶
func BuildJSONInstruction(prompt string, schema json.RawMessage) string
BuildJSONInstruction returns the instruction text that is injected into the system message. If prompt is non-empty it is kept as the first line. If schema is non-nil, the schema and schema-aware suffix are appended; otherwise a generic "answer with JSON" suffix is appended.
func InjectJSONInstruction ¶
InjectJSONInstruction returns a new message slice with JSON-formatting instructions merged into (or prepended as) a system message.
Mirrors ai-sdk's injectJsonInstructionIntoMessages. If the first message is a system message, its text is augmented; otherwise a new system message is prepended. The input slice is not mutated.
func MapReasoning ¶ added in v0.1.8
MapReasoning maps shared effort to supported wire values and reports lossy mappings. Empty and provider-default leave the provider's defaults untouched.
func OpenAIReasoning ¶ added in v0.1.8
OpenAIReasoning resolves explicit effort before the shared setting.
func ParseProviderOptions ¶
ParseProviderOptions parses a map[string]any into a typed options struct. This is a Go-idiomatic way to handle provider-specific options. Usage:
opts, err := provider.ParseProviderOptions[ResponsesOptions](options.ProviderOptions)
if err != nil {
return err
}
if opts.ReasoningEffort != "" {
req.Reasoning = &reasoningConfig{Effort: opts.ReasoningEffort}
}
func ReasoningBudget ¶ added in v0.1.8
ReasoningBudget derives a token budget from the model output limit.
func ValidateInlineOrURLFile ¶ added in v0.3.3
ValidateInlineOrURLFile checks an exact MIME allowlist and source shape. image/* is accepted only for URLs when explicitly present in the allowlist. It does not fetch, decode, rewrite, or mutate data.
func ValidateMessageContent ¶ added in v0.3.3
func ValidateMessageContent(messages []message.Message, validator FileValidator, siblingText bool, hostedReplay func(message.ToolResultPart) bool) error
ValidateMessageContent combines file checks with actual serializer placement rules. hostedReplay is nil for serializers without assistant hosted replay. A non-nil declaration must verify the provider's replay representation.
func ValidateMessageFiles ¶ added in v0.3.3
func ValidateMessageFiles(messages []message.Message, validator FileValidator) error
ValidateMessageFiles checks file shapes, not serializer placement admission. Hosts must additionally use the actual adapter's MessageValidator.
func ValidatePromptMessages ¶ added in v0.3.3
ValidatePromptMessages rejects structured input that prompt-only builders cannot represent. Plain Content.Text remains supported.
func ValidateTextToolMessages ¶ added in v0.3.3
ValidateTextToolMessages rejects all non-text tool content without imposing a user-role file contract on provider-specific converters.
Types ¶
type Capabilities ¶
type Capabilities struct {
Tools bool // Supports tool/function calling
Vision bool // Supports image input
Streaming bool // Supports streaming responses
Reasoning bool // Supports extended thinking/reasoning
Temperature bool // Supports temperature parameter
}
Capabilities describes what a model supports.
type EmbeddingProvider ¶
type EmbeddingProvider interface {
EmbeddingModel(modelID string) model.EmbeddingModel
}
EmbeddingProvider is a provider that supports embeddings.
type FileValidationFunc ¶ added in v0.3.3
FileValidationFunc adapts a validation function to FileValidator.
func (FileValidationFunc) ValidateFile ¶ added in v0.3.3
type FileValidator ¶ added in v0.3.3
FileValidator is an adapter's role-aware transport contract. Hosts must also enforce selected-model modalities, authorization and resource limits. An adapter without this interface does not declare file support. Complete-message content admission additionally requires MessageValidator.
type FilesProvider ¶ added in v0.1.7
FilesProvider is an optional provider-level file management capability.
type ImageProvider ¶
type ImageProvider interface {
ImageModel(modelID string) model.ImageModel
}
ImageProvider is a provider that supports image generation.
type LanguageProvider ¶
type LanguageProvider interface {
LanguageModel(modelID string) model.LanguageModel
}
LanguageProvider is a provider that supports language models. All providers must implement this.
type MessageValidator ¶ added in v0.3.3
MessageValidator is the authoritative complete-message admission contract. FileValidator and ValidateMessageFiles alone cannot establish whether a serializer supports a tool result's placement or sibling representation.
type ModelInfo ¶
type ModelInfo struct {
ID string
Name string
Provider string
ContextLimit int
OutputLimit int
Capabilities Capabilities
}
ModelInfo contains metadata about a model.
type Options ¶
type Options struct {
// APIKey is the API key for authentication.
APIKey string
// BaseURL overrides the default API endpoint.
BaseURL string
// Headers are additional HTTP headers to send.
Headers map[string]string
// Organization is the organization ID (for providers that support it).
Organization string
// Project is the project ID (for providers that support it, e.g., OpenAI).
Project string
}
Options contains common provider configuration.
type Provider ¶
type Provider interface {
// ID returns the provider identifier (e.g., "openai", "anthropic").
ID() string
// Model returns a language model instance for the given model ID.
// This is the primary method for getting a model.
Model(modelID string) stream.Model
// LanguageModel returns a language model instance.
// Returns nil if the model is not supported.
LanguageModel(modelID string) model.LanguageModel
// ImageModel returns an image generation model instance.
// Returns nil if the provider doesn't support image generation.
ImageModel(modelID string) model.ImageModel
// EmbeddingModel returns an embedding model instance.
// Returns nil if the provider doesn't support embeddings.
EmbeddingModel(modelID string) model.EmbeddingModel
// SpeechModel returns a text-to-speech model instance.
// Returns nil if the provider doesn't support speech generation.
SpeechModel(modelID string) model.SpeechModel
// TranscriptionModel returns a speech-to-text model instance.
// Returns nil if the provider doesn't support transcription.
TranscriptionModel(modelID string) model.TranscriptionModel
// RerankingModel returns a reranking model instance.
// Returns nil if the provider doesn't support reranking.
RerankingModel(modelID string) model.RerankingModel
}
Provider is the interface that all LLM providers must implement. At minimum, providers must implement LanguageModel support. Other model types are optional and return nil if not supported.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds registered providers.
type RerankingProvider ¶
type RerankingProvider interface {
RerankingModel(modelID string) model.RerankingModel
}
RerankingProvider is a provider that supports document reranking.
type SpeechProvider ¶
type SpeechProvider interface {
SpeechModel(modelID string) model.SpeechModel
}
SpeechProvider is a provider that supports text-to-speech.
type StreamInput ¶
StreamInput wraps the input for provider streaming.
type TranscriptionProvider ¶
type TranscriptionProvider interface {
TranscriptionModel(modelID string) model.TranscriptionModel
}
TranscriptionProvider is a provider that supports speech-to-text.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bedrock provides an Amazon Bedrock provider implementation.
|
Package bedrock provides an Amazon Bedrock provider implementation. |
|
Package anthropic provides an Anthropic provider implementation.
|
Package anthropic provides an Anthropic provider implementation. |
|
Package assemblyai provides an AssemblyAI provider implementation for transcription.
|
Package assemblyai provides an AssemblyAI provider implementation for transcription. |
|
Package azure provides an Azure OpenAI provider implementation.
|
Package azure provides an Azure OpenAI provider implementation. |
|
Package baseten provides a Baseten provider implementation.
|
Package baseten provides a Baseten provider implementation. |
|
Package blackforestlabs provides a Black Forest Labs (Flux) provider implementation.
|
Package blackforestlabs provides a Black Forest Labs (Flux) provider implementation. |
|
Package cerebras provides a Cerebras provider implementation.
|
Package cerebras provides a Cerebras provider implementation. |
|
Package cohere provides a Cohere provider implementation.
|
Package cohere provides a Cohere provider implementation. |
|
Package deepgram provides a Deepgram provider implementation for speech and transcription.
|
Package deepgram provides a Deepgram provider implementation for speech and transcription. |
|
Package deepinfra provides a DeepInfra provider implementation.
|
Package deepinfra provides a DeepInfra provider implementation. |
|
Package deepseek provides a DeepSeek provider implementation.
|
Package deepseek provides a DeepSeek provider implementation. |
|
Package elevenlabs provides an ElevenLabs provider implementation for speech generation.
|
Package elevenlabs provides an ElevenLabs provider implementation for speech generation. |
|
Package fal provides a fal.ai provider implementation for image generation.
|
Package fal provides a fal.ai provider implementation for image generation. |
|
Package fireworks provides a Fireworks AI provider implementation.
|
Package fireworks provides a Fireworks AI provider implementation. |
|
Package gladia provides a Gladia provider implementation for transcription.
|
Package gladia provides a Gladia provider implementation for transcription. |
|
Package google provides a Google AI (Gemini) provider implementation.
|
Package google provides a Google AI (Gemini) provider implementation. |
|
Package groq provides a Groq provider implementation.
|
Package groq provides a Groq provider implementation. |
|
Package huggingface provides a Hugging Face Inference API provider implementation.
|
Package huggingface provides a Hugging Face Inference API provider implementation. |
|
Package hume provides a Hume AI provider implementation for expressive speech.
|
Package hume provides a Hume AI provider implementation for expressive speech. |
|
Package lmnt provides an LMNT provider implementation for speech generation.
|
Package lmnt provides an LMNT provider implementation for speech generation. |
|
Package luma provides a Luma Labs provider implementation for video/image generation.
|
Package luma provides a Luma Labs provider implementation for video/image generation. |
|
Package mistral provides a Mistral AI provider implementation.
|
Package mistral provides a Mistral AI provider implementation. |
|
Package openai provides an OpenAI provider implementation.
|
Package openai provides an OpenAI provider implementation. |
|
Package openaicompat provides an OpenAI-compatible provider base.
|
Package openaicompat provides an OpenAI-compatible provider base. |
|
Package openresponses provides a configurable Responses API provider.
|
Package openresponses provides a configurable Responses API provider. |
|
Package openrouter implements the OpenRouter modalities whose wire format differs from OpenAI's, so they can't ride the embedded OpenAI provider:
|
Package openrouter implements the OpenRouter modalities whose wire format differs from OpenAI's, so they can't ride the embedded OpenAI provider: |
|
Package perplexity provides a Perplexity provider implementation.
|
Package perplexity provides a Perplexity provider implementation. |
|
Package prodia provides a Prodia provider implementation for image generation.
|
Package prodia provides a Prodia provider implementation for image generation. |
|
Package proxy implements a stream.Model that proxies LLM calls through an Airlock-compatible NDJSON endpoint (POST /api/agent/llm/stream).
|
Package proxy implements a stream.Model that proxies LLM calls through an Airlock-compatible NDJSON endpoint (POST /api/agent/llm/stream). |
|
Package replicate provides a Replicate provider implementation.
|
Package replicate provides a Replicate provider implementation. |
|
Package revai provides a Rev.ai provider implementation for transcription.
|
Package revai provides a Rev.ai provider implementation for transcription. |
|
Package togetherai provides a Together AI provider implementation.
|
Package togetherai provides a Together AI provider implementation. |
|
Package vertex provides a Google Vertex AI provider implementation.
|
Package vertex provides a Google Vertex AI provider implementation. |
|
Package vertexanthropic provides a Google Vertex AI Anthropic provider.
|
Package vertexanthropic provides a Google Vertex AI Anthropic provider. |
|
Package vertexmaas provides a Google Vertex AI MaaS (Model as a Service) provider.
|
Package vertexmaas provides a Google Vertex AI MaaS (Model as a Service) provider. |
|
Package voyage implements Voyage AI embeddings and reranking.
|
Package voyage implements Voyage AI embeddings and reranking. |
|
Package xai provides an xAI (Grok) provider implementation.
|
Package xai provides an xAI (Grok) provider implementation. |