router

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Combo

type Combo struct {
	Name     string   `json:"name"`
	Strategy string   `json:"strategy"` // "failover", "round_robin", "lowest_latency", "quota_weighted"
	Targets  []Target `json:"targets"`
	// contains filtered or unexported fields
}

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Clear added in v0.3.0

func (r *Router) Clear()

func (*Router) Execute

func (r *Router) Execute(ctx context.Context, req *providers.ChatRequest) (io.ReadCloser, bool, int, error)

Execute routes the request, executing automatic failover or load balancing

func (*Router) ExecuteEmbeddings added in v0.2.0

func (r *Router) ExecuteEmbeddings(ctx context.Context, req *providers.EmbeddingRequest) (*providers.EmbeddingResponse, error)

func (*Router) GetAllMetrics added in v0.3.0

func (r *Router) GetAllMetrics() map[string]TargetMetrics

func (*Router) GetAllProviders added in v0.3.0

func (r *Router) GetAllProviders() []providers.Provider

func (*Router) GetCombos added in v0.3.0

func (r *Router) GetCombos() map[string]*Combo

func (*Router) GetProvider added in v0.3.0

func (r *Router) GetProvider(id string) (providers.Provider, bool)

func (*Router) GetTargetMetrics added in v0.3.0

func (r *Router) GetTargetMetrics(providerID, model string) TargetMetrics

func (*Router) ListModels

func (r *Router) ListModels(ctx context.Context) ([]providers.ModelInfo, error)

func (*Router) RecordTargetLatency added in v0.3.0

func (r *Router) RecordTargetLatency(providerID, model string, latencyMs int64)

func (*Router) RegisterCombo

func (r *Router) RegisterCombo(name, strategy string, targets []Target)

func (*Router) RegisterProvider

func (r *Router) RegisterProvider(p providers.Provider)

func (*Router) ResolveTarget added in v0.3.0

func (r *Router) ResolveTarget(model string) (Target, bool)

func (*Router) SetTargetQuota added in v0.3.0

func (r *Router) SetTargetQuota(providerID, model string, percent float64)

type Target

type Target struct {
	ProviderID   string  `json:"provider_id"`
	Model        string  `json:"model"`
	QuotaPercent float64 `json:"quota_percent,omitempty"`
}

type TargetMetrics added in v0.3.0

type TargetMetrics struct {
	EWMALatencyMs float64   `json:"ewma_latency_ms"`
	SampleCount   int64     `json:"sample_count"`
	LastLatencyMs int64     `json:"last_latency_ms"`
	LastSuccessAt time.Time `json:"last_success_at"`
	QuotaPercent  float64   `json:"quota_percent"`
}

Jump to

Keyboard shortcuts

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