MCPcopy
hub / github.com/mudler/LocalAI / runRouterWithDeps

Function runRouterWithDeps

core/http/middleware/route_model_test.go:446–459  ·  view source on GitHub ↗

runRouterWithDeps is runRouter's general form: lets the caller pass a fully-populated ClassifierDeps (ModelLookup, Evaluator, ...) so tests can exercise the template-renderer + stop-token derivation paths, not just the bare-scorer fast path.

(loader *config.ModelConfigLoader, appConfig *config.ApplicationConfig, store router.DecisionStore, routerCfg *config.ModelConfig, parsed any, deps ClassifierDeps)

Source from the content-addressed store, hash-verified

444// tests can exercise the template-renderer + stop-token derivation
445// paths, not just the bare-scorer fast path.
446func runRouterWithDeps(loader *config.ModelConfigLoader, appConfig *config.ApplicationConfig, store router.DecisionStore, routerCfg *config.ModelConfig, parsed any, deps ClassifierDeps) (*httptest.ResponseRecorder, error) {
447 mw := RouteModel(loader, appConfig, store, nil, OpenAIProbe, router.SourceChat, deps)
448 req := httptest.NewRequest(http.MethodPost, "/v1/chat/completions", strings.NewReader("{}"))
449 rec := httptest.NewRecorder()
450 c := echo.New().NewContext(req, rec)
451 c.Set(CONTEXT_LOCALS_KEY_MODEL_CONFIG, routerCfg)
452 c.Set(CONTEXT_LOCALS_KEY_LOCALAI_REQUEST, parsed)
453 handler := mw(func(c echo.Context) error {
454 served, _ := c.Get(ContextKeyServedModel).(string)
455 return c.String(http.StatusOK, "served:"+served)
456 })
457 err := handler(c)
458 return rec, err
459}
460
461// loaderLookup mirrors application.ModelConfigLookup — bridges the
462// loader to the ModelConfigLookup signature ClassifierDeps wants.

Callers 2

runRouterFunction · 0.85

Calls 6

RouteModelFunction · 0.85
mwFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
handlerFunction · 0.50

Tested by

no test coverage detected