Skip to content

Commit b1cd840

Browse files
committed
feat: re-used defined variables from openai utils in modelrouter
1 parent c81a0ab commit b1cd840

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

pkg/controller/modelrouter/modelrouter_controller.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,34 @@ import (
3737
modelv1alpha1 "github.com/vllm-project/aibrix/api/model/v1alpha1"
3838
orchestrationv1alpha1 "github.com/vllm-project/aibrix/api/orchestration/v1alpha1"
3939
"github.com/vllm-project/aibrix/pkg/config"
40+
aibrixgateway "github.com/vllm-project/aibrix/pkg/plugins/gateway"
4041
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
4142
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
4243
)
4344

4445
const (
4546
// TODO (varun): cleanup model related identifiers and establish common consensus
46-
modelHeaderIdentifier = "model"
47-
modelIdentifier = "model.aibrix.ai/name"
48-
modelPortIdentifier = "model.aibrix.ai/port"
49-
modelSupportedRoutesIdentifier = "model.aibrix.ai/supported-routes"
50-
modelRouteEmbeddings = "embeddings"
51-
modelRouteChatCompletions = "chat-completions"
52-
modelRouteDefault = modelRouteChatCompletions
47+
modelHeaderIdentifier = "model"
48+
modelIdentifier = "model.aibrix.ai/name"
49+
modelPortIdentifier = "model.aibrix.ai/port"
50+
modelSupportedRequestTypeIdentifier = "model.aibrix.ai/supported-request-types"
5351
// TODO (varun): parameterize it or dynamically resolve it
5452
aibrixEnvoyGateway = "aibrix-eg"
5553
aibrixEnvoyGatewayNamespace = "aibrix-system"
5654

5755
defaultModelServingPort = 8000
5856
)
5957

58+
var (
59+
requestTypeIdentifierToSupportedRoutePathPrefix = map[string][]string{
60+
string(aibrixgateway.OpenAiRequestEmbeddingsType): {string(aibrixgateway.OpenAiRequestEmbeddingsPath)},
61+
string(aibrixgateway.OpenAiRequestChatCompletionsType): {string(aibrixgateway.OpenAiRequestCompletionsPath), string(aibrixgateway.OpenAiRequestChatCompletionsPath)},
62+
string(aibrixgateway.OpenAiRequestCompletionsType): {string(aibrixgateway.OpenAiRequestCompletionsPath), string(aibrixgateway.OpenAiRequestChatCompletionsPath)},
63+
}
64+
65+
defaultSupportedRequestType = string(aibrixgateway.OpenAiRequestChatCompletionsType)
66+
)
67+
6068
//+kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
6169
//+kubebuilder:rbac:groups=orchestration.aibrix.ai,resources=rayclusterfleets,verbs=get;list;watch;create;update;patch;delete
6270
//+kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=httproutes,verbs=get;list;watch;create;update;patch;delete
@@ -115,24 +123,19 @@ func Add(mgr manager.Manager, runtimeConfig config.RuntimeConfig) error {
115123

116124
// getSupportedRoutesMatchFromLabelsOrDefault returns the HTTPRouteMatch based on the model route labels value
117125
func getSupportedRoutesMatchFromLabelsOrDefault(labels map[string]string, modelHeaderMatch gatewayv1.HTTPHeaderMatch) []gatewayv1.HTTPRouteMatch {
118-
labelValueToRoutePathPrefix := map[string][]string{
119-
modelRouteEmbeddings: {"/v1/embeddings"},
120-
modelRouteChatCompletions: {"/v1/completions", "/v1/chat/completions"},
121-
}
122-
123126
var pathPrefixes []string
124-
if routesLabelValue, ok := labels[modelSupportedRoutesIdentifier]; ok {
125-
routes := strings.Split(routesLabelValue, ",")
126-
for k, route := range labelValueToRoutePathPrefix {
127-
if slices.Contains(routes, k) {
128-
pathPrefixes = append(pathPrefixes, route...)
127+
if routesLabelValue, ok := labels[modelSupportedRequestTypeIdentifier]; ok {
128+
routesIdentifier := strings.Split(routesLabelValue, ",")
129+
for id, paths := range requestTypeIdentifierToSupportedRoutePathPrefix {
130+
if slices.Contains(routesIdentifier, id) {
131+
pathPrefixes = append(pathPrefixes, paths...)
129132
}
130133
}
131134
}
132135

133136
// Add the default pathPrefixes if no route defines via labels
134137
if len(pathPrefixes) == 0 {
135-
pathPrefixes = append(pathPrefixes, labelValueToRoutePathPrefix[modelRouteDefault]...)
138+
pathPrefixes = append(pathPrefixes, requestTypeIdentifierToSupportedRoutePathPrefix[defaultSupportedRequestType]...)
136139
}
137140

138141
var routesmatch []gatewayv1.HTTPRouteMatch

0 commit comments

Comments
 (0)