MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getRouteHandler

Function getRouteHandler

internal/server/web/proxy/route.go:28–185  ·  view source on GitHub ↗
(prod bool, ca cache, aoe azureEstimator, e estimator, client http.Client, rec recorder)

Source from the content-addressed store, hash-verified

26}
27
28func getRouteHandler(prod bool, ca cache, aoe azureEstimator, e estimator, client http.Client, rec recorder) gin.HandlerFunc {
29 return func(c *gin.Context) {
30 log := util.GetLogFromCtx(c)
31 trueStart := time.Now()
32
33 tags := []string{
34 fmt.Sprintf("path:%s", c.FullPath()),
35 }
36
37 telemetry.Incr("bricksllm.proxy.get_route_handeler.requests", tags, 1)
38 if c == nil || c.Request == nil {
39 JSON(c, http.StatusInternalServerError, "[BricksLLM] context is empty")
40 return
41 }
42
43 raw, exists := c.Get("key")
44 kc, ok := raw.(*key.ResponseKey)
45 if !exists || !ok {
46 telemetry.Incr("bricksllm.proxy.get_route_handeler.api_key_not_registered", tags, 1)
47 JSON(c, http.StatusUnauthorized, "[BricksLLM] api key is not registered")
48 return
49 }
50
51 raw, exists = c.Get("route_config")
52 rc, ok := raw.(*route.Route)
53 if !exists || !ok {
54 telemetry.Incr("bricksllm.proxy.get_route_handeler.route_config_not_found", tags, 1)
55 JSON(c, http.StatusNotFound, "[BricksLLM] route config not found")
56 return
57 }
58
59 cacheKey := c.GetString("cache_key")
60 shouldCache := len(cacheKey) != 0
61
62 if shouldCache {
63 bytes, err := ca.GetBytes(cacheKey)
64
65 if err == nil && len(bytes) != 0 {
66 telemetry.Incr("bricksllm.proxy.get_route_handeler.success", nil, 1)
67 telemetry.Timing("bricksllm.proxy.get_route_handeler.success_latency", time.Since(trueStart), nil, 1)
68
69 c.Set("provider", "cached")
70 c.Data(http.StatusOK, "application/json", bytes)
71 return
72 }
73 }
74
75 raw, exists = c.Get("settings")
76 settings, ok := raw.([]*provider.Setting)
77 if !exists || !ok {
78 telemetry.Incr("bricksllm.proxy.get_route_handeler.provider_settings_not_found", tags, 1)
79 JSON(c, http.StatusNotFound, "[BricksLLM] provider settings not found")
80 return
81 }
82
83 settingsMap := map[string]*provider.Setting{}
84 for _, setting := range settings {
85 settingsMap[setting.Id] = setting

Callers 1

NewProxyServerFunction · 0.85

Calls 13

GetLogFromCtxFunction · 0.92
IncrFunction · 0.92
TimingFunction · 0.92
JSONFunction · 0.85
parseResultFunction · 0.85
logOpenAiErrorFunction · 0.85
RunStepsV2Method · 0.80
ShouldRunEmbeddingsMethod · 0.80
logErrorFunction · 0.70
GetMethod · 0.65
GetBytesMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected