From 8b741e58c7d04bcb1f4d44862d23d69fd6dc802d Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Sun, 15 Feb 2026 01:37:44 -0600 Subject: [PATCH] feat(gateway): priority sorted based on config definition --- llm-gateway/internal/provider/registry.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/llm-gateway/internal/provider/registry.go b/llm-gateway/internal/provider/registry.go index 1a15819..8b9d001 100644 --- a/llm-gateway/internal/provider/registry.go +++ b/llm-gateway/internal/provider/registry.go @@ -19,6 +19,7 @@ type Route struct { // Registry maps model names to provider routes. type Registry struct { routes map[string][]Route + order []string // preserves config order } func NewRegistry(cfg *config.Config) (*Registry, error) { @@ -28,8 +29,9 @@ func NewRegistry(cfg *config.Config) (*Registry, error) { providers[pc.Name] = NewOpenAIProvider(pc.Name, pc.BaseURL, pc.APIKey, pc.Timeout) } - // Build routes + // Build routes (preserving config order) routes := make(map[string][]Route) + order := make([]string, 0, len(cfg.Models)) for _, mc := range cfg.Models { var modelRoutes []Route for _, rc := range mc.Routes { @@ -52,9 +54,10 @@ func NewRegistry(cfg *config.Config) (*Registry, error) { return modelRoutes[i].Priority < modelRoutes[j].Priority }) routes[mc.Name] = modelRoutes + order = append(order, mc.Name) } - return &Registry{routes: routes}, nil + return &Registry{routes: routes, order: order}, nil } // Lookup returns the routes for a model name. @@ -63,12 +66,7 @@ func (r *Registry) Lookup(model string) ([]Route, bool) { return routes, ok } -// ModelNames returns all registered model names. +// ModelNames returns all registered model names in config order. func (r *Registry) ModelNames() []string { - names := make([]string, 0, len(r.routes)) - for name := range r.routes { - names = append(names, name) - } - sort.Strings(names) - return names + return r.order }