Documentation
¶
Index ¶
- Constants
- Variables
- func FetchModelContextWindow(ctx context.Context, providerType, baseURL, apiKey, modelID string) int
- func ListModels(ctx context.Context, reg Registry) ([]ModelInfo, []Warning, error)
- func LookupModelContextWindow(ctx context.Context, providerType, baseURL, apiKey, modelID string) int
- func NewClient(cfg config.ProviderConfig) (llm.Client, error)
- func NewClientFromRuntime(cfg config.ProviderRuntimeConfig, health HealthChecker) (llm.Client, error)
- func NewRoutedClient(router Router) llm.Client
- func NewRoutedClientWithPolicy(router Router, health HealthChecker, allowFallback bool) llm.Client
- func NewRouterClient(cfg config.ProviderRuntimeConfig, health HealthChecker) (llm.Client, error)
- func WithRouteContext(ctx context.Context, rc RouteContext) context.Context
- type Anthropic
- type AssistantToolCallContentMode
- type Availability
- type Client
- type Config
- type Error
- type ErrorCode
- type Event
- type EventType
- type ExternalHealthTicker
- type Gemini
- type HealthChecker
- type HealthConfig
- type HealthSnapshot
- type HealthStatus
- type ModelID
- type ModelInfo
- type ModelMetadata
- type ModelRegistry
- type OpenAICompatible
- type ProviderID
- type ReasoningReplayMode
- type Registry
- type Request
- type ResolvedModelPolicy
- type RouteContext
- type RouteResult
- type RouteTarget
- type RoutedClient
- type Router
- type RouterConfig
- type Usage
- type Warning
Constants ¶
View Source
const ( ModelPolicySourceDefault = "default" ModelPolicySourceFamilyOverride = "family" ModelPolicySourceProviderID = "provider_id" ModelPolicySourceBaseURL = "base_url" )
Variables ¶
View Source
var ( ErrProviderNotFound = errors.New(string(ErrCodeProviderNotFound)) ErrDuplicateProvider = errors.New(string(ErrCodeDuplicateProvider)) )
Functions ¶
func FetchModelContextWindow ¶ added in v1.0.1
func FetchModelContextWindow(ctx context.Context, providerType, baseURL, apiKey, modelID string) int
FetchModelContextWindow queries the provider API for a model's context window. Returns 0 if the provider doesn't support querying this info.
func ListModels ¶
func LookupModelContextWindow ¶ added in v1.0.1
func LookupModelContextWindow(ctx context.Context, providerType, baseURL, apiKey, modelID string) int
LookupModelContextWindow checks the known table first, then tries the provider API.
func NewClientFromRuntime ¶
func NewClientFromRuntime(cfg config.ProviderRuntimeConfig, health HealthChecker) (llm.Client, error)
func NewRoutedClient ¶
func NewRoutedClientWithPolicy ¶
func NewRoutedClientWithPolicy(router Router, health HealthChecker, allowFallback bool) llm.Client
func NewRouterClient ¶
func NewRouterClient(cfg config.ProviderRuntimeConfig, health HealthChecker) (llm.Client, error)
func WithRouteContext ¶
func WithRouteContext(ctx context.Context, rc RouteContext) context.Context
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
func NewAnthropic ¶
func (*Anthropic) CreateMessage ¶
type AssistantToolCallContentMode ¶
type AssistantToolCallContentMode string
const ( AssistantToolCallContentPreserve AssistantToolCallContentMode = "preserve" AssistantToolCallContentEmptyString AssistantToolCallContentMode = "empty_string" AssistantToolCallContentNull AssistantToolCallContentMode = "null" AssistantToolCallContentOmit AssistantToolCallContentMode = "omit" )
type Availability ¶
func CheckAvailability ¶
func CheckAvailability(ctx context.Context, cfg config.ProviderConfig) Availability
type Client ¶
type Client interface {
ProviderID() ProviderID
ListModels(ctx context.Context) ([]ModelInfo, error)
Stream(ctx context.Context, req Request) (<-chan Event, error)
}
func NewDomainClient ¶
func NewDomainClient(cfg config.ProviderConfig) (Client, error)
func NewDomainClientWithID ¶
func NewDomainClientWithID(providerID ProviderID, cfg config.ProviderConfig) (Client, error)
func WrapClient ¶
func WrapClient(providerID ProviderID, defaultModel ModelID, client llm.Client) Client
type Error ¶
type ExternalHealthTicker ¶
type ExternalHealthTicker struct {
// contains filtered or unexported fields
}
func NewExternalHealthTicker ¶
func NewExternalHealthTicker(health HealthChecker, ids func(context.Context) ([]ProviderID, error)) *ExternalHealthTicker
type Gemini ¶
type Gemini struct {
// contains filtered or unexported fields
}
func (*Gemini) CreateMessage ¶
type HealthChecker ¶
type HealthChecker interface {
Check(ctx context.Context, id ProviderID) error
Status(ctx context.Context, id ProviderID) HealthSnapshot
RecordSuccess(ctx context.Context, id ProviderID)
RecordFailure(ctx context.Context, id ProviderID, err error)
}
func NewHealthChecker ¶
func NewHealthChecker(cfg HealthConfig, checker func(context.Context, ProviderID) error) HealthChecker
type HealthConfig ¶
type HealthConfig struct {
FailThreshold int
RecoverProbeSec int
RecoverSuccessThreshold int
WindowSize int
}
func HealthConfigFromRuntime ¶
func HealthConfigFromRuntime(cfg config.ProviderHealthRuntimeConfig) HealthConfig
type HealthSnapshot ¶
type HealthStatus ¶
type HealthStatus string
const ( HealthStatusHealthy HealthStatus = "healthy" HealthStatusDegraded HealthStatus = "degraded" HealthStatusHalfOpen HealthStatus = "half_open" )
type ModelInfo ¶
type ModelInfo struct {
ProviderID ProviderID
ModelID ModelID
DisplayAlias string
Metadata map[string]string
}
func (ModelInfo) ModelMetadata ¶ added in v0.1.8
func (m ModelInfo) ModelMetadata() ModelMetadata
type ModelMetadata ¶ added in v0.1.8
type ModelRegistry ¶ added in v0.1.8
type ModelRegistry struct {
// contains filtered or unexported fields
}
func NewModelRegistry ¶ added in v0.1.8
func NewModelRegistry(runtimeCfg config.ProviderRuntimeConfig, discovered []ModelInfo) ModelRegistry
func (ModelRegistry) ContextWindow ¶ added in v0.1.8
func (r ModelRegistry) ContextWindow(providerID ProviderID, modelID ModelID) int
func (ModelRegistry) Lookup ¶ added in v0.1.8
func (r ModelRegistry) Lookup(providerID ProviderID, modelID ModelID) (ModelInfo, bool)
func (ModelRegistry) Models ¶ added in v0.1.8
func (r ModelRegistry) Models() []ModelInfo
type OpenAICompatible ¶
type OpenAICompatible struct {
// contains filtered or unexported fields
}
func NewOpenAICompatible ¶
func NewOpenAICompatible(cfg Config) *OpenAICompatible
func (*OpenAICompatible) CreateMessage ¶
func (c *OpenAICompatible) CreateMessage(ctx context.Context, req llm.ChatRequest) (llm.Message, error)
func (*OpenAICompatible) StreamMessage ¶
func (c *OpenAICompatible) StreamMessage(ctx context.Context, req llm.ChatRequest, onDelta func(string)) (llm.Message, error)
type ProviderID ¶
type ProviderID string
const ( ProviderOpenAI ProviderID = "openai" ProviderAnthropic ProviderID = "anthropic" ProviderGemini ProviderID = "gemini" ProviderMock ProviderID = "mock" )
type ReasoningReplayMode ¶
type ReasoningReplayMode string
const ( ReasoningReplayNone ReasoningReplayMode = "none" ReasoningReplayHiddenField ReasoningReplayMode = "hidden_field" )
type Registry ¶
type Registry interface {
Register(ctx context.Context, client Client) error
Get(ctx context.Context, id ProviderID) (Client, bool)
List(ctx context.Context) ([]ProviderID, error)
}
func NewRegistry ¶
func NewRegistry(cfg config.ProviderRuntimeConfig) (Registry, error)
func NewRegistryFromProviderConfig ¶
func NewRegistryFromProviderConfig(cfg config.ProviderConfig) (Registry, error)
type ResolvedModelPolicy ¶
type ResolvedModelPolicy struct {
ProviderID ProviderID
ProviderType string
ModelID ModelID
Family string
AssistantToolCallContentMode AssistantToolCallContentMode
ReasoningField string
ReasoningReplayMode ReasoningReplayMode
Source string
}
func ResolveModelPolicy ¶
func ResolveModelPolicy(providerID ProviderID, providerType string, modelID ModelID, family string, baseURL string) ResolvedModelPolicy
func (ResolvedModelPolicy) ReplayReasoning ¶
func (p ResolvedModelPolicy) ReplayReasoning() bool
type RouteContext ¶
type RouteContext struct {
Scenario string
Region string
PreferLatency bool
PreferLowCost bool
AllowFallback bool
Tags map[string]string
}
func RouteContextFromContext ¶
func RouteContextFromContext(ctx context.Context) RouteContext
type RouteResult ¶
type RouteResult struct {
Primary RouteTarget
Fallbacks []RouteTarget
}
type RouteTarget ¶
type RouteTarget struct {
ProviderID ProviderID
ModelID ModelID
Client Client
}
type RoutedClient ¶
type RoutedClient struct {
// contains filtered or unexported fields
}
func (*RoutedClient) CreateMessage ¶
func (c *RoutedClient) CreateMessage(ctx context.Context, req llm.ChatRequest) (llm.Message, error)
func (*RoutedClient) StreamMessage ¶
func (c *RoutedClient) StreamMessage(ctx context.Context, req llm.ChatRequest, onDelta func(string)) (llm.Message, error)
type Router ¶
type Router interface {
Route(ctx context.Context, requestedModel ModelID, rc RouteContext) (RouteResult, error)
}
func NewRouter ¶
func NewRouter(reg Registry, health HealthChecker, cfg RouterConfig) Router
type RouterConfig ¶
type RouterConfig struct {
DefaultProvider ProviderID
DefaultModel ModelID
}
type Warning ¶
type Warning struct {
ProviderID ProviderID
Reason string
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.