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
3 changes: 2 additions & 1 deletion examples/configs/withframework/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"framework": {
"pricing": {
"pricing_url": "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json",
"pricing_sync_interval": 86400
"pricing_sync_interval": 86400,
"model_parameters_url": "https://getbifrost.ai/datasheet/model-parameters"
}
},
"providers": {
Expand Down
3 changes: 2 additions & 1 deletion examples/dockers/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"framework": {
"pricing": {
"pricing_url": "https://getbifrost.ai/datasheet",
"pricing_sync_interval": 86400
"pricing_sync_interval": 86400,
"model_parameters_url": "https://getbifrost.ai/datasheet/model-parameters"
}
}
}
31 changes: 31 additions & 0 deletions framework/configstore/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@ func triggerMigrations(ctx context.Context, db *gorm.DB) error {
if err := migrationAddFeatureFlagsTable(ctx, db); err != nil {
return err
}
if err := migrationAddModelParametersURLColumn(ctx, db); err != nil {
return err
}
if err := migrationAddClientConfigMetadataColumn(ctx, db); err != nil {
return err
}
Expand Down Expand Up @@ -7800,3 +7803,31 @@ func migrationAddVKAccessProfileIDColumn(ctx context.Context, db *gorm.DB) error
}
return nil
}

func migrationAddModelParametersURLColumn(ctx context.Context, db *gorm.DB) error {
m := migrator.New(db, migrator.DefaultOptions, []*migrator.Migration{{
ID: "add_model_parameters_url_column",
Migrate: func(tx *gorm.DB) error {
tx = tx.WithContext(ctx)
mig := tx.Migrator()
if !mig.HasColumn(&tables.TableFrameworkConfig{}, "model_parameters_url") {
if err := mig.AddColumn(&tables.TableFrameworkConfig{}, "ModelParametersURL"); err != nil {
return fmt.Errorf("failed to add model_parameters_url column to framework_configs: %w", err)
}
}
return nil
},
Rollback: func(tx *gorm.DB) error {
tx = tx.WithContext(ctx)
mig := tx.Migrator()
if mig.HasColumn(&tables.TableFrameworkConfig{}, "model_parameters_url") {
return mig.DropColumn(&tables.TableFrameworkConfig{}, "model_parameters_url")
}
return nil
},
}})
if err := m.Migrate(); err != nil {
return fmt.Errorf("error running add_model_parameters_url_column migration: %s", err.Error())
}
return nil
}
1 change: 1 addition & 0 deletions framework/configstore/tables/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type TableFrameworkConfig struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
PricingURL *string `gorm:"type:text" json:"pricing_url"`
PricingSyncInterval *int64 `gorm:"" json:"pricing_sync_interval"`
ModelParametersURL *string `gorm:"type:text" json:"model_parameters_url"`
}

// TableName sets the table name for each model
Expand Down
1 change: 1 addition & 0 deletions framework/modelcatalog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ const (
type Config struct {
PricingURL *string `json:"pricing_url,omitempty"`
PricingSyncInterval *int64 `json:"pricing_sync_interval,omitempty"` // seconds
ModelParametersURL *string `json:"model_parameters_url,omitempty"`
}
25 changes: 21 additions & 4 deletions framework/modelcatalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type ModelCatalog struct {
logger schemas.Logger

// Configuration fields (protected by syncMu)
pricingURL string
syncInterval time.Duration
lastSyncedAt time.Time
syncMu sync.RWMutex
pricingURL string
modelParametersURL string
syncInterval time.Duration
lastSyncedAt time.Time
syncMu sync.RWMutex

shouldSyncGate func(ctx context.Context) bool
afterSyncHook func(ctx context.Context)
Expand Down Expand Up @@ -69,6 +70,10 @@ func Init(ctx context.Context, config *Config, configStore configstore.ConfigSto
if config.PricingURL != nil {
pricingURL = *config.PricingURL
}
modelParametersURL := DefaultModelParametersURL
if config.ModelParametersURL != nil && *config.ModelParametersURL != "" {
modelParametersURL = *config.ModelParametersURL
}
syncInterval := DefaultSyncInterval
if config.PricingSyncInterval != nil {
syncInterval = time.Duration(*config.PricingSyncInterval) * time.Second
Expand All @@ -81,6 +86,7 @@ func Init(ctx context.Context, config *Config, configStore configstore.ConfigSto

mc := &ModelCatalog{
pricingURL: pricingURL,
modelParametersURL: modelParametersURL,
syncInterval: syncInterval,
configStore: configStore,
logger: logger,
Expand Down Expand Up @@ -272,6 +278,11 @@ func (mc *ModelCatalog) UpdateSyncConfig(ctx context.Context, config *Config) er
mc.pricingURL = *config.PricingURL
}

mc.modelParametersURL = DefaultModelParametersURL
if config.ModelParametersURL != nil && *config.ModelParametersURL != "" {
mc.modelParametersURL = *config.ModelParametersURL
}

mc.syncInterval = DefaultSyncInterval
if config.PricingSyncInterval != nil {
mc.syncInterval = time.Duration(*config.PricingSyncInterval) * time.Second
Expand Down Expand Up @@ -354,6 +365,12 @@ func (mc *ModelCatalog) getPricingURL() string {
return mc.pricingURL
}

func (mc *ModelCatalog) getModelParametersURL() string {
mc.syncMu.RLock()
defer mc.syncMu.RUnlock()
return mc.modelParametersURL
}

// IsRequestTypeSupported checks if a model supports chat completion.
// It checks the supportedResponseTypes index.
func (mc *ModelCatalog) IsRequestTypeSupported(model string, provider schemas.ModelProvider, requestType schemas.RequestType) bool {
Expand Down
2 changes: 1 addition & 1 deletion framework/modelcatalog/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (mc *ModelCatalog) syncModelParameters(ctx context.Context) error {
func (mc *ModelCatalog) loadModelParametersFromURL(ctx context.Context) (map[string]json.RawMessage, error) {
client := &http.Client{}
client.Timeout = DefaultModelParametersTimeout
req, err := http.NewRequestWithContext(ctx, http.MethodGet, DefaultModelParametersURL, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, mc.getModelParametersURL(), nil)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions helm-charts/bifrost/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ false
{{- if .Values.bifrost.framework.pricing.pricingUrl }}
{{- $_ := set $pricing "pricing_url" .Values.bifrost.framework.pricing.pricingUrl }}
{{- end }}
{{- if .Values.bifrost.framework.pricing.modelParametersUrl }}
{{- $_ := set $pricing "model_parameters_url" .Values.bifrost.framework.pricing.modelParametersUrl }}
{{- end }}
{{- if .Values.bifrost.framework.pricing.pricingSyncInterval }}
{{- $_ := set $pricing "pricing_sync_interval" .Values.bifrost.framework.pricing.pricingSyncInterval }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions helm-charts/bifrost/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@
"type": "string",
"description": "Custom pricing URL (optional, can be empty)"
},
"modelParametersUrl": {
"type": "string",
"description": "Custom model parameters URL (optional, can be empty)"
},
"pricingSyncInterval": {
"type": "integer",
"description": "Pricing sync interval in seconds. Default is 24 hours. Minimum is 3600 seconds (1 hour).",
Expand Down
2 changes: 2 additions & 0 deletions helm-charts/bifrost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ bifrost:
pricing:
# Custom pricing URL for model cost data
pricingUrl: "https://getbifrost.ai/datasheet"
# Custom model parameters URL
modelParametersUrl: "https://getbifrost.ai/datasheet/model-parameters"
# Sync interval in seconds (default: 86400 = 24 hours, minimum: 3600)
pricingSyncInterval: 86400

Expand Down
45 changes: 45 additions & 0 deletions transports/bifrost-http/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
return
}
}
if payload.FrameworkConfig.ModelParametersURL != nil && *payload.FrameworkConfig.ModelParametersURL != "" && *payload.FrameworkConfig.ModelParametersURL != modelcatalog.DefaultModelParametersURL {
urlCheckClient := &http.Client{Timeout: 60 * time.Second}
resp, err := urlCheckClient.Get(*payload.FrameworkConfig.ModelParametersURL)
if err != nil {
logger.Warn("failed to check the accessibility of the model parameters URL: %v", err)
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("failed to check the accessibility of the model parameters URL: %v", err))
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
logger.Warn("failed to check the accessibility of the model parameters URL: %v", resp.StatusCode)
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("failed to check the accessibility of the model parameters URL: %v", resp.StatusCode))
return
}
}

// Checking the pricing sync interval
if payload.FrameworkConfig.PricingSyncInterval != nil && *payload.FrameworkConfig.PricingSyncInterval <= 0 {
Expand Down Expand Up @@ -535,6 +550,7 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
ID: 0,
PricingURL: bifrost.Ptr(modelcatalog.DefaultPricingURL),
PricingSyncInterval: bifrost.Ptr(int64(modelcatalog.DefaultSyncInterval.Seconds())),
ModelParametersURL: bifrost.Ptr(modelcatalog.DefaultModelParametersURL),
}
}
// Handling individual nil cases
Expand All @@ -544,6 +560,9 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
if frameworkConfig.PricingSyncInterval == nil {
frameworkConfig.PricingSyncInterval = bifrost.Ptr(int64(modelcatalog.DefaultSyncInterval.Seconds()))
}
if frameworkConfig.ModelParametersURL == nil {
frameworkConfig.ModelParametersURL = bifrost.Ptr(modelcatalog.DefaultModelParametersURL)
}
// Updating framework config
shouldReloadFrameworkConfig := false
if payload.FrameworkConfig.PricingURL != nil && *payload.FrameworkConfig.PricingURL != *frameworkConfig.PricingURL {
Expand All @@ -570,6 +589,31 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
shouldReloadFrameworkConfig = true
}
}
if payload.FrameworkConfig.ModelParametersURL != nil {
effectiveModelParamsURL := *payload.FrameworkConfig.ModelParametersURL
if effectiveModelParamsURL == "" {
effectiveModelParamsURL = modelcatalog.DefaultModelParametersURL
}
if effectiveModelParamsURL != *frameworkConfig.ModelParametersURL {
if effectiveModelParamsURL != modelcatalog.DefaultModelParametersURL {
urlCheckClient := &http.Client{Timeout: 60 * time.Second}
resp, err := urlCheckClient.Get(effectiveModelParamsURL)
if err != nil {
logger.Warn("failed to check the accessibility of the model parameters URL: %v", err)
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("failed to check the accessibility of the model parameters URL: %v", err))
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
logger.Warn("failed to check the accessibility of the model parameters URL: %v", resp.StatusCode)
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("failed to check the accessibility of the model parameters URL: %v", resp.StatusCode))
return
}
}
frameworkConfig.ModelParametersURL = &effectiveModelParamsURL
shouldReloadFrameworkConfig = true
}
}
// Reload config if required
if shouldReloadFrameworkConfig {
var syncSeconds int64
Expand All @@ -582,6 +626,7 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
Pricing: &modelcatalog.Config{
PricingURL: frameworkConfig.PricingURL,
PricingSyncInterval: &syncSeconds,
ModelParametersURL: frameworkConfig.ModelParametersURL,
},
}
// Saving framework config
Expand Down
Loading
Loading