provider

package
v0.0.2-0...-50f8182 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package provider composes LLM provider clients for Anthropic, OpenAI, and OpenAI-compatible APIs with streaming, retry, and provider detection.

Index

Constants

This section is empty.

Variables

Version mirrors core.Version; the canonical value lives in provider/core so feature packages can build User-Agent strings. Default is generated from the canonical VERSION file.

Functions

func DetectProvider

func DetectProvider() string

DetectProvider detects the active provider from the credential store.

func NewAudioMessage

func NewAudioMessage(base64Data, format string) core.MuxMessage

NewAudioMessage creates a user message with base64-encoded audio. format should be "wav" or "mp3".

func NewAudioMessageWithText

func NewAudioMessageWithText(text, base64Data, format string) core.MuxMessage

NewAudioMessageWithText creates a user message with text and base64-encoded audio.

func NewBase64ImageMessage

func NewBase64ImageMessage(data, mediaType string) core.MuxMessage

NewBase64ImageMessage creates a user message with a base64-encoded image. mediaType should be a MIME type like "image/png" or "image/jpeg".

func NewBase64ImageMessageWithText

func NewBase64ImageMessageWithText(text, data, mediaType string) core.MuxMessage

NewBase64ImageMessageWithText creates a user message with text and a base64-encoded image.

func NewImageMessage

func NewImageMessage(url string) core.MuxMessage

NewImageMessage creates a user message with an image from a URL or data URI. The url parameter accepts HTTP(S) URLs or data URIs (data:image/png;base64,...).

func NewImageMessageWithText

func NewImageMessageWithText(text, url string) core.MuxMessage

NewImageMessageWithText creates a user message with text and an image from a URL or data URI.

func ParseCustomHeaders

func ParseCustomHeaders() map[string]string

ParseCustomHeaders parses MUX_CUSTOM_HEADERS env var into a map.

func ResolveDefaultModel

func ResolveDefaultModel(provider string) string

ResolveDefaultModel resolves the default model for a provider from the catalog.

func ResolveProviderModelEnvOverride

func ResolveProviderModelEnvOverride(provider string) string

ResolveProviderModelEnvOverride resolves the model env override for a provider.

func SetVersion

func SetVersion(v string)

SetVersion wires the canonical version from the VERSION file into the provider runtime and provider/core.

func WithAPIKey

func WithAPIKey(key string) core.ClientOption

WithAPIKey sets the API key.

func WithBaseURL

func WithBaseURL(url string) core.ClientOption

WithBaseURL sets the base URL.

func WithCoalescing

func WithCoalescing(ttl time.Duration) core.ClientOption

WithCoalescing enables request coalescing for identical concurrent requests. When enabled, multiple goroutines sending identical requests (same provider, model, messages, temperature, max_tokens) will be deduplicated into a single API call, with the result broadcast to all waiters.

The ttl parameter controls how long completed requests remain in the coalescer for potential reuse. A typical value is 100-500ms.

func WithGuardrailType

func WithGuardrailType(types ...core.GuardrailType) core.ClientOption

WithGuardrailType attaches output guardrails using built-in rules for the specified types. For example, WithGuardrailType(GuardrailPII, GuardrailSecretLeak) enables PII redaction and secret leak blocking with default patterns.

func WithGuardrails

func WithGuardrails(rules ...core.GuardrailRule) core.ClientOption

WithGuardrails attaches output guardrails to the provider. core.Guardrails run after the LLM response but before returning to the caller. Blocked responses are replaced with an error; redacted responses have matches replaced with asterisks.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) core.ClientOption

WithHTTPClient sets a custom HTTP provider.

func WithLogger

func WithLogger(l *slog.Logger) core.ClientOption

WithLogger sets the logger.

func WithMaxTokens

func WithMaxTokens(n int) core.ClientOption

WithMaxTokens sets the default max tokens for requests.

func WithMimoAuth

func WithMimoAuth() core.ClientOption

WithMimoAuth uses api-key header per MiMo documentation (OpenAI + Anthropic compat).

func WithModel

func WithModel(model string) core.ClientOption

WithModel sets the default model for requests.

func WithProviderName

func WithProviderName(name string) core.ClientOption

WithProviderName sets the OpenAI client provider name for errors/logging. No-op for the Anthropic adapter, which reports a fixed provider name.

func WithRetry

func WithRetry(rc core.RetryConfig) core.ClientOption

WithRetry sets retry configuration.

func WithTemperature

func WithTemperature(t float64) core.ClientOption

WithTemperature sets the default temperature for requests.

func WithTimeout

func WithTimeout(d time.Duration) core.ClientOption

WithTimeout sets the HTTP client timeout.

Types

type AnthropicClientConfig

type AnthropicClientConfig struct {
	APIKey         string            `json:"-"`
	DefaultHeaders map[string]string `json:"default_headers,omitempty"`
	Timeout        int               `json:"timeout,omitempty"`
	MaxRetries     int               `json:"max_retries,omitempty"`
	Provider       string            `json:"provider,omitempty"`
	BaseURL        string            `json:"base_url,omitempty"`
}

AnthropicClientConfig holds config for creating an Anthropic provider.

type LazyProvider

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

LazyProvider adapts MuxClient to the core.Provider interface without eagerly resolving credentials or constructing a concrete provider.

func NewLazyProvider

func NewLazyProvider(cfg *core.MuxConfig) *LazyProvider

NewLazyProvider creates a provider wrapper that resolves the concrete provider only when chat or ping operations are invoked.

func (*LazyProvider) Chat

func (p *LazyProvider) Chat(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions) (*core.MuxResponse, error)

func (*LazyProvider) Name

func (p *LazyProvider) Name() string

func (*LazyProvider) Ping

func (p *LazyProvider) Ping(ctx context.Context) error

func (*LazyProvider) SetAPIKey

func (p *LazyProvider) SetAPIKey(provider, apiKey string)

func (*LazyProvider) StreamChat

func (p *LazyProvider) StreamChat(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions) (*core.StreamResult, error)

type MuxClient

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

MuxClient is the universal LLM provider. It is safe for concurrent use.

func Client

func Client(cfg *core.MuxConfig, opts ...core.ClientOption) *MuxClient

Client creates an MuxClient.

func (*MuxClient) Chat

func (c *MuxClient) Chat(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions) (*core.MuxResponse, error)

Chat sends a chat request to the specified (or default) provider.

func (*MuxClient) ChatWithStructuredOutput

func (c *MuxClient) ChatWithStructuredOutput(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions, validation core.SchemaValidation) (*core.MuxResponse, error)

ChatWithStructuredOutput validates structured JSON responses while retaining MuxClient's provider resolution and default-model behavior. The schema, validation, prompting, and retry implementation lives in provider/media.

func (*MuxClient) CreateEmbedding

func (c *MuxClient) CreateEmbedding(ctx context.Context, req embeddings.EmbeddingRequest, provider string) (*embeddings.EmbeddingResponse, error)

CreateEmbedding sends an embedding request to the specified (or default) provider.

func (*MuxClient) ExtractRelationships

func (c *MuxClient) ExtractRelationships(ctx context.Context, text string, opts extraction.ExtractOptions) ([]extraction.Relationship, error)

ExtractRelationships delegates relationship extraction to the extraction feature while retaining MuxClient's public convenience method.

func (*MuxClient) GetProviderInfo

func (c *MuxClient) GetProviderInfo(provider string) *adapters.ProviderRegistryConfig

GetProviderInfo returns config for a provider.

func (*MuxClient) GetProviders

func (c *MuxClient) GetProviders() []string

GetProviders lists all available providers.

func (*MuxClient) Ping

func (c *MuxClient) Ping(ctx context.Context, provider string) error

Ping checks connectivity to the specified (or default) provider.

func (*MuxClient) RegisterCustomProvider

func (c *MuxClient) RegisterCustomProvider(name, baseURL, envKey string) error

RegisterCustomProvider adds an OpenAI-compatible endpoint to this client only. Re-registration replaces the endpoint and invalidates its cached transport. Other clients are unaffected.

func (*MuxClient) SetAPIKey

func (c *MuxClient) SetAPIKey(provider, apiKey string)

SetAPIKey sets an API key for a provider.

func (*MuxClient) SetCoalescingTTL

func (c *MuxClient) SetCoalescingTTL(ttl time.Duration)

SetCoalescingTTL enables request coalescing with the given reuse TTL. Implements core.MuxConfigurable for WithCoalescing.

func (*MuxClient) StreamChat

func (c *MuxClient) StreamChat(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions) (*core.StreamResult, error)

StreamChat sends a streaming chat request.

func (*MuxClient) StreamChatContinue

func (c *MuxClient) StreamChatContinue(ctx context.Context, messages []core.MuxMessage, opts core.ChatOptions, cfg core.ContinuationConfig) (*core.StreamResult, error)

StreamChatContinue is like StreamChat but automatically continues if the response hits max_tokens with text-only content. Continuations are transparent to the caller.

Directories

Path Synopsis
Package core holds the provider contract and the data types shared by every layer of the mux client: adapters, middleware, caching, embeddings, and the provider runtime itself.
Package core holds the provider contract and the data types shared by every layer of the mux client: adapters, middleware, caching, embeddings, and the provider runtime itself.
Package client provides request coalescing for identical concurrent LLM requests.
Package client provides request coalescing for identical concurrent LLM requests.

Jump to

Keyboard shortcuts

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