Skip to content

Commit 5c886d2

Browse files
committed
feat: explicitely set default route option
1 parent db75780 commit 5c886d2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pkg/controller/modelrouter/modelrouter_controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const (
4747
modelIdentifier = "model.aibrix.ai/name"
4848
modelPortIdentifier = "model.aibrix.ai/port"
4949
modelSupportedRoutesIdentifier = "model.aibrix.ai/supported-routes"
50-
modelEmbeddingsRoute = "embeddings"
51-
modelChatCompletionsRoute = "chat-completions"
50+
modelRouteEmbeddings = "embeddings"
51+
modelRouteChatCompletions = "chat-completions"
52+
modelRouteDefault = modelRouteChatCompletions
5253
// TODO (varun): parameterize it or dynamically resolve it
5354
aibrixEnvoyGateway = "aibrix-eg"
5455
aibrixEnvoyGatewayNamespace = "aibrix-system"
@@ -112,25 +113,26 @@ func Add(mgr manager.Manager, runtimeConfig config.RuntimeConfig) error {
112113
return err
113114
}
114115

116+
// getSupportedRoutesMatchFromLabelsOrDefault returns the HTTPRouteMatch based on the model route labels value
115117
func getSupportedRoutesMatchFromLabelsOrDefault(labels map[string]string, modelHeaderMatch gatewayv1.HTTPHeaderMatch) []gatewayv1.HTTPRouteMatch {
116-
nameToRoutePathPrefix := map[string][]string{
117-
modelEmbeddingsRoute: {"/v1/embeddings"},
118-
modelChatCompletionsRoute: {"/v1/completions", "/v1/chat/completions"},
118+
labelValueToRoutePathPrefix := map[string][]string{
119+
modelRouteEmbeddings: {"/v1/embeddings"},
120+
modelRouteChatCompletions: {"/v1/completions", "/v1/chat/completions"},
119121
}
120122

121123
var pathPrefixes []string
122124
if routesLabelValue, ok := labels[modelSupportedRoutesIdentifier]; ok {
123125
routes := strings.Split(routesLabelValue, ",")
124-
for k, route := range nameToRoutePathPrefix {
126+
for k, route := range labelValueToRoutePathPrefix {
125127
if slices.Contains(routes, k) {
126128
pathPrefixes = append(pathPrefixes, route...)
127129
}
128130
}
129131
}
130132

131-
// completions and chat completions routes by default
133+
// Add the default pathPrefixes if no route defines via labels
132134
if len(pathPrefixes) == 0 {
133-
pathPrefixes = append(pathPrefixes, nameToRoutePathPrefix[modelChatCompletionsRoute]...)
135+
pathPrefixes = append(pathPrefixes, labelValueToRoutePathPrefix[modelRouteDefault]...)
134136
}
135137

136138
var routesmatch []gatewayv1.HTTPRouteMatch

0 commit comments

Comments
 (0)