@@ -4,13 +4,16 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7- "github.com/bricks-cloud/bricksllm/internal/provider/xcustom"
87 "io"
98 "net/http"
109 "strconv"
1110 "strings"
1211 "time"
1312
13+ "github.com/bricks-cloud/bricksllm/internal/provider/azure"
14+ "github.com/bricks-cloud/bricksllm/internal/provider/deepinfra"
15+ "github.com/bricks-cloud/bricksllm/internal/provider/xcustom"
16+
1417 "github.com/bricks-cloud/bricksllm/internal/event"
1518 "github.com/bricks-cloud/bricksllm/internal/key"
1619 "github.com/bricks-cloud/bricksllm/internal/message"
@@ -938,6 +941,12 @@ func getMiddleware(cpm CustomProvidersManager, rm routeManager, pm PoliciesManag
938941 c .Abort ()
939942 return
940943 }
944+ if ! isModelSupported (c .FullPath (), model ) {
945+ telemetry .Incr ("bricksllm.proxy.get_middleware.model_not_supported" , nil , 1 )
946+ JSON (c , http .StatusBadRequest , "[BricksLLM] model is not supported" )
947+ c .Abort ()
948+ return
949+ }
941950
942951 aid := c .Param ("assistant_id" )
943952 fid := c .Param ("file_id" )
@@ -1332,6 +1341,67 @@ func containsPath(arr []key.PathConfig, path, method string) bool {
13321341 return true
13331342 }
13341343 }
1344+ return false
1345+ }
1346+
1347+ var openaiModels = map [string ]struct {}{}
1348+ var anthropicModels = map [string ]struct {}{}
1349+ var azureOpenAIModels = map [string ]struct {}{}
1350+ var vllmModels = map [string ]struct {}{}
1351+ var deepinfraModels = map [string ]struct {}{}
1352+ var bedrockAnthropicModels = map [string ]struct {}{}
1353+
1354+ func init () {
1355+ // openai models
1356+ initByCostMap (openaiModels , openai .OpenAiPerThousandTokenCost )
1357+ // anthropic models
1358+ initByCostMap (anthropicModels , anthropic .AnthropicPerMillionTokenCost )
1359+ // azure openai models
1360+ initByCostMap (azureOpenAIModels , azure .AzureOpenAiPerThousandTokenCost )
1361+ // deepinfra models
1362+ initByCostMap (deepinfraModels , deepinfra .DeepinfraPerMillionTokenCost )
1363+ // TODO: check vllm and bedrock anthropic models
1364+ // cost map from settings
1365+ // maybe disable this models or...
1366+ }
1367+
1368+ func initByCostMap (target map [string ]struct {}, source map [string ]map [string ]float64 ) {
1369+ for _ , m := range source {
1370+ for k , _ := range m {
1371+ target [k ] = struct {}{}
1372+ }
1373+ }
1374+ }
13351375
1376+ func isModelSupported (path , model string ) bool {
1377+ models := modelsMapByPath (path )
1378+ if models == nil {
1379+ return true
1380+ }
1381+ if _ , ok := models [model ]; ok {
1382+ return true
1383+ }
13361384 return false
13371385}
1386+
1387+ func modelsMapByPath (path string ) map [string ]struct {} {
1388+ if strings .HasPrefix (path , "/api/providers/openai" ) {
1389+ return openaiModels
1390+ }
1391+ if strings .HasPrefix (path , "/api/providers/anthropic" ) {
1392+ return anthropicModels
1393+ }
1394+ if strings .HasPrefix (path , "/api/providers/azure/openai" ) {
1395+ return azureOpenAIModels
1396+ }
1397+ if strings .HasPrefix (path , "/api/providers/vllm" ) {
1398+ return vllmModels
1399+ }
1400+ if strings .HasPrefix (path , "/api/providers/deepinfra" ) {
1401+ return deepinfraModels
1402+ }
1403+ if strings .HasPrefix (path , "/api/providers/bedrock/anthropic" ) {
1404+ return bedrockAnthropicModels
1405+ }
1406+ return nil
1407+ }
0 commit comments