Documentation
¶
Index ¶
- Constants
- Variables
- func DrainBody(r io.ReadCloser)
- func SetDefaultHTTPTimeout(d time.Duration)
- func StreamResponse(ctx context.Context, rc io.ReadCloser) iter.Seq2[[]byte, error]
- func StreamSSE(ctx context.Context, rc io.ReadCloser) iter.Seq2[[]byte, error]
- func ValidateProviderOptions(provider string, options map[string]any) error
- type AwsBedrock
- type Azure
- type AzureAuthMode
- type Client
- type CohereOptions
- type Config
- type ConnectionTester
- type Credentials
- type EmbeddingsClient
- type HTTPClientPool
- type OpenAICompatibleOptions
- type OpenAIOptions
- type ProbeResult
- func ClassifyProbeStatus(statusCode int) ProbeResult
- func ClassifyProbeStatusForProvider(providerKey string, statusCode int) ProbeResult
- func RunAPIKeyGETProbe(ctx context.Context, providerKey string, url string, apiKey string, ...) ProbeResult
- func RunBearerGETProbe(ctx context.Context, providerKey, url, apiKey string) ProbeResult
- func RunHTTPProbe(providerKey string, req *http.Request) ProbeResult
- type ProbeStage
- type RerankClient
- type VertexOptions
Constants ¶
const ( ProviderOpenAI = provider.OpenAI ProviderOpenAICompatible = provider.OpenAICompatible ProviderGoogle = provider.Google ProviderVertex = provider.Vertex ProviderAnthropic = provider.Anthropic ProviderBedrock = provider.Bedrock ProviderAzure = provider.Azure ProviderMistral = provider.Mistral ProviderGroq = provider.Groq ProviderDeepSeek = provider.DeepSeek ProviderXAI = provider.XAI ProviderCerebras = provider.Cerebras ProviderOpenRouter = provider.OpenRouter ProviderCohere = provider.Cohere )
Provider name constants. Use these as keys for HTTPClientPool.Get() and anywhere a provider needs to be identified by name. They alias the domain provider source of truth.
const ( OpenAIAPICompletions = "completions" OpenAIAPIResponses = "responses" )
const ProbeHTTPTimeout = 10 * time.Second
const StreamTimeout = 5 * time.Minute
StreamTimeout bounds the total duration of a single streamed response.
Variables ¶
var DefaultHTTPTimeout = 120 * time.Second
DefaultHTTPTimeout is the timeout used by all provider HTTP clients. Override with SetDefaultHTTPTimeout during initialization.
Functions ¶
func DrainBody ¶
func DrainBody(r io.ReadCloser)
DrainBody reads and discards up to 64 KB of remaining data from r, then closes it. This ensures the underlying TCP connection is returned cleanly to the transport's pool and is never reused with stale data. Callers should use this in error paths where the body was only partially read (e.g. after io.CopyN for an error preview).
func SetDefaultHTTPTimeout ¶
func StreamResponse ¶
Types ¶
type AwsBedrock ¶
type AwsBedrock struct {
Region string `json:"region"`
AccessKey string `json:"access_key"` // #nosec G117 -- DTO field for AWS access key configuration
SecretKey string `json:"secret_key"` // #nosec G117 -- DTO field for AWS secret key configuration
SessionToken string `json:"session_token"` // #nosec G117 -- DTO field for AWS session token configuration
UseRole bool `json:"use_role"`
RoleARN string `json:"role_arn"`
}
type Azure ¶
type Azure struct {
Endpoint string `json:"endpoint"`
ApiVersion string `json:"api_version"`
AuthMode AzureAuthMode `json:"auth_mode"`
UseIdentity bool `json:"use_identity"`
TenantID string `json:"tenant_id"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"` // #nosec G117 -- Azure client secret credential
}
type AzureAuthMode ¶
type AzureAuthMode string
const ( AzureAuthModeAPIKey AzureAuthMode = "api_key" AzureAuthModeServicePrincipal AzureAuthMode = "service_principal" AzureAuthModeDefaultAzureCredential AzureAuthMode = "default_azure_credential" // #nosec G101 -- auth mode identifier, not a credential value )
type Client ¶
type Client interface {
Completions(
ctx context.Context,
config *Config,
reqBody []byte,
) ([]byte, error)
// CompletionsStream performs the streaming request. The outer error carries
// pre-stream failures (e.g. a registry.BackendError on a non-2xx response, for
// verbatim passthrough). The returned sequence yields raw SSE lines and
// surfaces mid-stream read errors as the second value.
CompletionsStream(
ctx context.Context,
config *Config,
reqBody []byte,
) (iter.Seq2[[]byte, error], error)
}
type CohereOptions ¶ added in v0.3.4
type CohereOptions struct {
BaseURL string `mapstructure:"base_url"`
}
func DecodeCohereOptions ¶ added in v0.3.4
func DecodeCohereOptions(options map[string]any) (CohereOptions, error)
type Config ¶
type Config struct {
Credentials Credentials `json:"credentials"`
AllowedModels []string `json:"allowed_models"`
DefaultModel string `json:"default_model"`
Model string `json:"model"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
SystemPrompt string `json:"system_prompt,omitempty"`
Instructions []string `json:"instructions,omitempty"`
Options map[string]any `json:"options,omitempty"`
}
type ConnectionTester ¶
type ConnectionTester interface {
TestConnection(ctx context.Context, config *Config) ProbeResult
}
type Credentials ¶
type Credentials struct {
ApiKey string `json:"api_key"` // #nosec G117 -- DTO field for provider API key configuration
AwsBedrock *AwsBedrock `json:"aws,omitempty"`
Azure *Azure `json:"azure,omitempty"`
}
func CredentialsFromTargetAuth ¶ added in v0.3.4
func CredentialsFromTargetAuth(a *registry.TargetAuth) Credentials
CredentialsFromTargetAuth maps a registry target's auth configuration onto the provider credentials DTO consumed by the provider clients.
type EmbeddingsClient ¶ added in v0.3.4
type EmbeddingsClient interface {
Embeddings(ctx context.Context, config *Config, reqBody []byte) ([]byte, error)
}
EmbeddingsClient performs non-streaming embedding requests.
type HTTPClientPool ¶
type HTTPClientPool struct {
// contains filtered or unexported fields
}
HTTPClientPool manages a pool of *http.Client instances keyed by provider name. It uses singleflight to ensure only one client is created per key even under concurrent access.
Each *http.Client returned is safe for concurrent use: Go's http.Client.Do() creates a completely independent HTTP transaction per call — there is no request/response caching between calls. The underlying Transport reuses TCP connections (keep-alive) for performance, but each request gets its own HTTP round-trip with its own headers, body, and response.
func NewHTTPClientPool ¶
func NewHTTPClientPool() *HTTPClientPool
NewHTTPClientPool returns a ready-to-use pool.
func (*HTTPClientPool) Get ¶
Get returns (or lazily creates) an *http.Client for the given key with the specified timeout. Typical keys are provider names ("openai", "anthropic", etc.) so each provider gets its own client and transport instance.
func (*HTTPClientPool) GetStream ¶
func (p *HTTPClientPool) GetStream(key string) *http.Client
GetStream returns an *http.Client suitable for SSE streaming. Unlike Get, it has no overall client timeout (a streamed response can outlive DefaultHTTPTimeout); callers bound the stream with a context deadline instead. Stream clients are pooled under a distinct key so they never share the non-streaming client's timeout.
type OpenAICompatibleOptions ¶
type OpenAICompatibleOptions struct {
BaseURL string `mapstructure:"base_url"`
Headers map[string]string `mapstructure:"headers"`
}
func DecodeOpenAICompatibleOptions ¶
func DecodeOpenAICompatibleOptions(options map[string]any) (OpenAICompatibleOptions, error)
type OpenAIOptions ¶
type OpenAIOptions struct {
API string `mapstructure:"api"`
BaseURL string `mapstructure:"base_url"`
}
func DecodeOpenAIOptions ¶
func DecodeOpenAIOptions(options map[string]any) (OpenAIOptions, error)
type ProbeResult ¶
type ProbeResult struct {
OK bool
Stage ProbeStage
StatusCode int
Message string
}
func ClassifyProbeStatus ¶
func ClassifyProbeStatus(statusCode int) ProbeResult
func ClassifyProbeStatusForProvider ¶
func ClassifyProbeStatusForProvider(providerKey string, statusCode int) ProbeResult
func RunAPIKeyGETProbe ¶
func RunBearerGETProbe ¶
func RunBearerGETProbe(ctx context.Context, providerKey, url, apiKey string) ProbeResult
func RunHTTPProbe ¶
func RunHTTPProbe(providerKey string, req *http.Request) ProbeResult
type ProbeStage ¶
type ProbeStage string
const ( StageConnectivity ProbeStage = "connectivity" StageAuthentication ProbeStage = "authentication" StageProvider ProbeStage = "provider" StageUnsupported ProbeStage = "unsupported" )
type RerankClient ¶ added in v0.3.4
type RerankClient interface {
Rerank(ctx context.Context, config *Config, reqBody []byte) ([]byte, error)
}
RerankClient performs non-streaming rerank requests.
type VertexOptions ¶
type VertexOptions struct {
Project string `mapstructure:"project"`
Location string `mapstructure:"location"`
Version string `mapstructure:"version"`
}
func DecodeVertexOptions ¶
func DecodeVertexOptions(options map[string]any) (VertexOptions, error)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package openaicompat implements a provider client for arbitrary OpenAI-compatible Chat Completions endpoints (Together, Fireworks, vLLM, Ollama, self-hosted gateways, ...).
|
Package openaicompat implements a provider client for arbitrary OpenAI-compatible Chat Completions endpoints (Together, Fireworks, vLLM, Ollama, self-hosted gateways, ...). |