@@ -3,6 +3,7 @@ package provider
3
3
import (
4
4
"errors"
5
5
"math/rand"
6
+ "strings"
6
7
7
8
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
8
9
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
@@ -253,16 +254,38 @@ func CreateProvider(pc ProviderConfig) (Provider, error) {
253
254
}
254
255
255
256
func getMappedModel (model string , modelMapping map [string ]string , log wrapper.Log ) string {
257
+ mappedModel := doGetMappedModel (model , modelMapping , log )
258
+ if len (mappedModel ) != 0 {
259
+ return mappedModel
260
+ }
261
+ return model
262
+ }
263
+
264
+ func doGetMappedModel (model string , modelMapping map [string ]string , log wrapper.Log ) string {
256
265
if modelMapping == nil || len (modelMapping ) == 0 {
257
- return model
266
+ return ""
258
267
}
259
- if v , ok := modelMapping [model ]; ok && len (v ) != 0 {
260
- log .Debugf ("model %s is mapped to %s explictly" , model , v )
268
+
269
+ if v , ok := modelMapping [model ]; ok {
270
+ log .Debugf ("model [%s] is mapped to [%s] explictly" , model , v )
261
271
return v
262
272
}
273
+
274
+ for k , v := range modelMapping {
275
+ if k == wildcard || ! strings .HasSuffix (k , wildcard ) {
276
+ continue
277
+ }
278
+ k = strings .TrimSuffix (k , wildcard )
279
+ if strings .HasPrefix (model , k ) {
280
+ log .Debugf ("model [%s] is mapped to [%s] via prefix [%s]" , model , v , k )
281
+ return v
282
+ }
283
+ }
284
+
263
285
if v , ok := modelMapping [wildcard ]; ok {
264
- log .Debugf ("model %s is mapped to %s via wildcard" , model , v )
286
+ log .Debugf ("model [%s] is mapped to [%s] via wildcard" , model , v )
265
287
return v
266
288
}
267
- return model
289
+
290
+ return ""
268
291
}
0 commit comments