Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions core/internal/llmtests/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context,
{
Models: []string{"*"},
Weight: 1.0,
Aliases: map[string]string{
"claude-3.7-sonnet": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"claude-4-sonnet": "global.anthropic.claude-sonnet-4-20250514-v1:0",
"claude-4.5-sonnet": "global.anthropic.claude-sonnet-4-5-20250929-v1:0",
"claude-4.6-sonnet": "global.anthropic.claude-sonnet-4-6",
"claude-4.5-haiku": "global.anthropic.claude-haiku-4-5-20251001-v1:0",
Aliases: schemas.KeyAliases{
"claude-3.7-sonnet": {ModelID: "us.anthropic.claude-3-7-sonnet-20250219-v1:0"},
"claude-4-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-20250514-v1:0"},
"claude-4.5-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-5-20250929-v1:0"},
"claude-4.6-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-6"},
"claude-4.5-haiku": {ModelID: "global.anthropic.claude-haiku-4-5-20251001-v1:0"},
},
BedrockKeyConfig: &schemas.BedrockKeyConfig{
AccessKey: *schemas.NewEnvVar("env.AWS_ACCESS_KEY_ID"),
Expand All @@ -259,13 +259,13 @@ func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context,
{
Models: []string{"*"},
Weight: 1.0,
Aliases: map[string]string{
"claude-3.5-sonnet": "anthropic.claude-3-5-sonnet-20240620-v1:0",
"claude-3.7-sonnet": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"claude-4-sonnet": "global.anthropic.claude-sonnet-4-20250514-v1:0",
"claude-4.5-sonnet": "global.anthropic.claude-sonnet-4-5-20250929-v1:0",
"claude-4.6-sonnet": "global.anthropic.claude-sonnet-4-6",
"claude-4.5-haiku": "global.anthropic.claude-haiku-4-5-20251001-v1:0",
Aliases: schemas.KeyAliases{
"claude-3.5-sonnet": {ModelID: "anthropic.claude-3-5-sonnet-20240620-v1:0"},
"claude-3.7-sonnet": {ModelID: "us.anthropic.claude-3-7-sonnet-20250219-v1:0"},
"claude-4-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-20250514-v1:0"},
"claude-4.5-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-5-20250929-v1:0"},
"claude-4.6-sonnet": {ModelID: "global.anthropic.claude-sonnet-4-6"},
"claude-4.5-haiku": {ModelID: "global.anthropic.claude-haiku-4-5-20251001-v1:0"},
},
BedrockKeyConfig: &schemas.BedrockKeyConfig{
AccessKey: *schemas.NewEnvVar("env.AWS_ACCESS_KEY_ID"),
Expand Down Expand Up @@ -303,13 +303,13 @@ func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context,
Models: []string{"*"},
Weight: 1.0,
Aliases: schemas.KeyAliases{
"gpt-4o": "gpt-4o",
"gpt-4o-backup": "gpt-4o-3",
"claude-opus-4-5": "claude-opus-4-5",
"o1": "o1",
"gpt-image-1": "gpt-image-1",
"text-embedding-ada-002": "text-embedding-ada-002",
"sora-2": "sora-2",
"gpt-4o": {ModelID: "gpt-4o"},
"gpt-4o-backup": {ModelID: "gpt-4o-3"},
"claude-opus-4-5": {ModelID: "claude-opus-4-5"},
"o1": {ModelID: "o1"},
"gpt-image-1": {ModelID: "gpt-image-1"},
"text-embedding-ada-002": {ModelID: "text-embedding-ada-002"},
"sora-2": {ModelID: "sora-2"},
},
AzureKeyConfig: &schemas.AzureKeyConfig{
Endpoint: *schemas.NewEnvVar("env.AZURE_ENDPOINT"),
Expand All @@ -324,10 +324,10 @@ func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context,
Models: []string{"*"},
Weight: 1.0,
Aliases: schemas.KeyAliases{
"whisper": "whisper",
"whisper-1": "whisper",
"gpt-4o-mini-tts": "gpt-4o-mini-tts",
"gpt-4o-mini-audio-preview": "gpt-4o-mini-audio-preview",
"whisper": {ModelID: "whisper"},
"whisper-1": {ModelID: "whisper"},
"gpt-4o-mini-tts": {ModelID: "gpt-4o-mini-tts"},
"gpt-4o-mini-audio-preview": {ModelID: "gpt-4o-mini-audio-preview"},
},
AzureKeyConfig: &schemas.AzureKeyConfig{
Endpoint: *schemas.NewEnvVar("env.AZURE_ENDPOINT"),
Expand Down Expand Up @@ -365,9 +365,9 @@ func (account *ComprehensiveTestAccount) GetKeysForProvider(ctx context.Context,
Models: []string{"claude-sonnet-4-5", "claude-4.5-haiku", "claude-opus-4-5"},
Weight: 1.0,
Aliases: schemas.KeyAliases{
"claude-sonnet-4-5": "claude-sonnet-4-5",
"claude-4.5-haiku": "claude-haiku-4-5@20251001",
"claude-opus-4-5": "claude-opus-4-5",
"claude-sonnet-4-5": {ModelID: "claude-sonnet-4-5"},
"claude-4.5-haiku": {ModelID: "claude-haiku-4-5@20251001"},
"claude-opus-4-5": {ModelID: "claude-opus-4-5"},
},
VertexKeyConfig: &schemas.VertexKeyConfig{
ProjectID: *schemas.NewEnvVar("env.VERTEX_PROJECT_ID"),
Expand Down
2 changes: 1 addition & 1 deletion core/providers/anthropic/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/maximhq/bifrost/core/schemas"
)

func (response *AnthropicListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *AnthropicListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/azure/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/maximhq/bifrost/core/schemas"
)

func (response *AzureListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *AzureListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/bedrock/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type BedrockRerankResponseDocument struct {
TextDocument *BedrockRerankTextValue `json:"textDocument,omitempty"`
}

func (response *BedrockListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *BedrockListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/providers/bedrock/rerank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestBedrockRerankRequestToBifrostRerankRequestNil(t *testing.T) {
func TestResolveBedrockDeployment(t *testing.T) {
key := schemas.Key{
Aliases: schemas.KeyAliases{
"cohere-rerank": "arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0",
"cohere-rerank": {ModelID: "arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0"},
},
}

Expand All @@ -211,7 +211,7 @@ func TestBedrockRerankRequiresARNModelIdentifier(t *testing.T) {
ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
key := schemas.Key{
Aliases: schemas.KeyAliases{
"cohere-rerank": "cohere.rerank-v3-5:0",
"cohere-rerank": {ModelID: "cohere.rerank-v3-5:0"},
},
}

Expand Down
2 changes: 1 addition & 1 deletion core/providers/cohere/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type CohereRerankMeta struct {
Tokens *CohereTokenUsage `json:"tokens,omitempty"`
}

func (response *CohereListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *CohereListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/elevenlabs/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/maximhq/bifrost/core/schemas"
)

func (response *ElevenlabsListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *ElevenlabsListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/gemini/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func toGeminiModelResourceName(modelID string) string {
return "models/" + modelID
}

func (response *GeminiListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *GeminiListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/huggingface/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
maxModelFetchLimit = 1000
)

func (response *HuggingFaceListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, inferenceProvider inferenceProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *HuggingFaceListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, inferenceProvider inferenceProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/mistral/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/maximhq/bifrost/core/schemas"
)

func (response *MistralListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *MistralListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/providers/openai/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// ToBifrostListModelsResponse converts an OpenAI list models response to a Bifrost list models response
func (response *OpenAIListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *OpenAIListModelsResponse) ToBifrostListModelsResponse(providerKey schemas.ModelProvider, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions core/providers/openrouter/openrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ func (provider *OpenRouterProvider) listModelsByKey(ctx *schemas.BifrostContext,
for _, m := range key.BlacklistedModels {
normalizedBlacklist = append(normalizedBlacklist, stripPrefix(m))
}
normalizedAliases := make(map[string]string, len(key.Aliases))
normalizedAliases := make(schemas.KeyAliases, len(key.Aliases))
for k, v := range key.Aliases {
normalizedAliases[stripPrefix(k)] = stripPrefix(v)
cfg := v
cfg.ModelID = stripPrefix(v.ModelID)
normalizedAliases[stripPrefix(k)] = cfg
}

pipeline := &providerUtils.ListModelsPipeline{
Expand Down
2 changes: 1 addition & 1 deletion core/providers/replicate/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ToBifrostListModelsResponse(
providerKey schemas.ModelProvider,
allowedModels schemas.WhiteList,
blacklistedModels schemas.BlackList,
aliases map[string]string,
aliases schemas.KeyAliases,
unfiltered bool,
) *schemas.BifrostListModelsResponse {
bifrostResponse := &schemas.BifrostListModelsResponse{
Expand Down
20 changes: 10 additions & 10 deletions core/providers/utils/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ type FilterResult struct {
type ListModelsPipeline struct {
AllowedModels schemas.WhiteList
BlacklistedModels schemas.BlackList
// Aliases maps user-facing alias keys to provider-specific model IDs.
// e.g. {"my-gpt4": "gpt-4-turbo-2024-04-09"}
Aliases map[string]string
// Aliases maps user-facing alias keys to their AliasConfig. The pipeline
// reads AliasConfig.ModelID for matching and Alias surfacing.
Aliases schemas.KeyAliases
Unfiltered bool
ProviderKey schemas.ModelProvider
// MatchFns is the ordered list of equivalence functions used for every
Expand Down Expand Up @@ -224,9 +224,9 @@ type aliasMatch struct {
// → [{key:"gpt-3.5-turbo", value:""}]
func (p *ListModelsPipeline) resolveModelID(modelID string) []aliasMatch {
var candidates []aliasMatch
for aliasKey, providerID := range p.Aliases {
if matches(modelID, providerID, p.MatchFns) {
candidates = append(candidates, aliasMatch{key: aliasKey, value: providerID})
for aliasKey, alias := range p.Aliases {
if matches(modelID, alias.ModelID, p.MatchFns) {
candidates = append(candidates, aliasMatch{key: aliasKey, value: alias.ModelID})
}
}
if len(candidates) == 0 {
Expand Down Expand Up @@ -369,9 +369,9 @@ func (p *ListModelsPipeline) BackfillModels(included map[string]bool) []schemas.
Name: schemas.Ptr(ToDisplayName(entry)),
}
// If this allowlist entry has an alias, surface the provider-specific ID.
for aliasKey, providerID := range p.Aliases {
for aliasKey, alias := range p.Aliases {
if matches(entry, aliasKey, p.MatchFns) {
m.Alias = schemas.Ptr(providerID)
m.Alias = schemas.Ptr(alias.ModelID)
break
}
}
Expand All @@ -382,7 +382,7 @@ func (p *ListModelsPipeline) BackfillModels(included map[string]bool) []schemas.

// Case B: wildcard allowlist — backfill only explicitly configured aliases.
if !p.Unfiltered && len(p.Aliases) > 0 {
for aliasKey, providerID := range p.Aliases {
for aliasKey, alias := range p.Aliases {
if included[strings.ToLower(aliasKey)] {
continue
}
Expand All @@ -400,7 +400,7 @@ func (p *ListModelsPipeline) BackfillModels(included map[string]bool) []schemas.
result = append(result, schemas.Model{
ID: string(p.ProviderKey) + "/" + aliasKey,
Name: schemas.Ptr(ToDisplayName(aliasKey)),
Alias: schemas.Ptr(providerID),
Alias: schemas.Ptr(alias.ModelID),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/providers/vertex/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type vertexRerankOptions struct {
// - If allowedModels is empty, all models are allowed
// - If allowedModels is non-empty, only models/deployments with keys in allowedModels are included
// - Deployments map is used to match model IDs to aliases and filter accordingly
func (response *VertexListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *VertexListModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func (response *VertexListModelsResponse) ToBifrostListModelsResponse(allowedMod

// ToBifrostListModelsResponse converts a Vertex AI publisher models response to Bifrost's format.
// This is for foundation models from the Model Garden (publishers.models.list endpoint).
func (response *VertexListPublisherModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases map[string]string, unfiltered bool) *schemas.BifrostListModelsResponse {
func (response *VertexListPublisherModelsResponse) ToBifrostListModelsResponse(allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList, aliases schemas.KeyAliases, unfiltered bool) *schemas.BifrostListModelsResponse {
if response == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/providers/vertex/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func vertexServiceTierHeaderValue(region string, model string, tier schemas.Bifr

// buildResponseFromConfig builds a list models response from configured deployments and allowedModels.
// This is used when the user has explicitly configured which models they want to use.
func buildResponseFromConfig(deployments map[string]string, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList) *schemas.BifrostListModelsResponse {
func buildResponseFromConfig(deployments schemas.KeyAliases, allowedModels schemas.WhiteList, blacklistedModels schemas.BlackList) *schemas.BifrostListModelsResponse {
response := &schemas.BifrostListModelsResponse{
Data: make([]schemas.Model, 0),
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func buildResponseFromConfig(deployments map[string]string, allowedModels schema
modelEntry := schemas.Model{
ID: modelID,
Name: schemas.Ptr(modelName),
Alias: schemas.Ptr(deploymentValue),
Alias: schemas.Ptr(deploymentValue.ModelID),
}

response.Data = append(response.Data, modelEntry)
Expand Down
Loading
Loading