52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package elevenlabs
|
|
|
|
import (
|
|
"strings"
|
|
|
|
providerUtils "github.com/maximhq/bifrost/core/providers/utils"
|
|
"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 {
|
|
if response == nil {
|
|
return nil
|
|
}
|
|
|
|
bifrostResponse := &schemas.BifrostListModelsResponse{
|
|
Data: make([]schemas.Model, 0, len(*response)),
|
|
}
|
|
|
|
pipeline := &providerUtils.ListModelsPipeline{
|
|
AllowedModels: allowedModels,
|
|
BlacklistedModels: blacklistedModels,
|
|
Aliases: aliases,
|
|
Unfiltered: unfiltered,
|
|
ProviderKey: providerKey,
|
|
MatchFns: providerUtils.DefaultMatchFns(),
|
|
}
|
|
if pipeline.ShouldEarlyExit() {
|
|
return bifrostResponse
|
|
}
|
|
|
|
included := make(map[string]bool)
|
|
|
|
for _, model := range *response {
|
|
for _, result := range pipeline.FilterModel(model.ModelID) {
|
|
entry := schemas.Model{
|
|
ID: string(providerKey) + "/" + result.ResolvedID,
|
|
Name: schemas.Ptr(model.Name),
|
|
}
|
|
if result.AliasValue != "" {
|
|
entry.Alias = schemas.Ptr(result.AliasValue)
|
|
}
|
|
bifrostResponse.Data = append(bifrostResponse.Data, entry)
|
|
included[strings.ToLower(result.ResolvedID)] = true
|
|
}
|
|
}
|
|
|
|
bifrostResponse.Data = append(bifrostResponse.Data,
|
|
pipeline.BackfillModels(included)...)
|
|
|
|
return bifrostResponse
|
|
}
|