Skip to content
Closed
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
19 changes: 19 additions & 0 deletions core/schemas/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ type ImageTokenDetails struct {
TextTokens int `json:"text_tokens,omitempty"`
}

// DeepCopy returns an independent copy of u with no shared pointer fields,
// safe for callers (e.g. cost calculation) that need to derive values
// without mutating the original response. Returns nil for a nil receiver.
func (u *ImageUsage) DeepCopy() *ImageUsage {
if u == nil {
return nil
}
out := *u
if u.InputTokensDetails != nil {
details := *u.InputTokensDetails
out.InputTokensDetails = &details
}
if u.OutputTokensDetails != nil {
details := *u.OutputTokensDetails
out.OutputTokensDetails = &details
}
return &out
}

// Streaming Response
type BifrostImageGenerationStreamResponse struct {
ID string `json:"id,omitempty"`
Expand Down
223 changes: 0 additions & 223 deletions framework/modelcatalog/capabilities_test.go

This file was deleted.

71 changes: 57 additions & 14 deletions framework/modelcatalog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@ package modelcatalog

import (
"time"

"github.com/maximhq/bifrost/core/schemas"
"github.com/maximhq/bifrost/framework/modelcatalog/datasheet"
"github.com/maximhq/bifrost/framework/modelcatalog/keyconfig"
)

const (
DefaultSyncInterval = 24 * time.Hour
DefaultSyncInterval = datasheet.DefaultSyncInterval
MinimumPricingSyncIntervalSec = int64(3600)

// syncWorkerTickerPeriod is the fixed interval at which the background sync worker
// wakes up to check whether a sync is due. This is independent of pricingSyncInterval —
// the ticker defines the check granularity, not the sync frequency.
// Kept well below MinimumPricingSyncIntervalSec so the threshold check is not
// defeated by ticker drift when pricingSyncInterval is set near the minimum.
syncWorkerTickerPeriod = 5 * time.Minute

ConfigLastPricingSyncKey = "LastModelPricingSync"
ConfigLastParamsSyncKey = "LastModelParametersSync"
DefaultPricingURL = "https://getbifrost.ai/datasheet"
DefaultModelParametersURL = "https://getbifrost.ai/datasheet/model-parameters"
DefaultPricingTimeout = 45 * time.Second
DefaultModelParametersTimeout = 45 * time.Second
ConfigLastPricingSyncKey = "LastModelPricingSync"
ConfigLastParamsSyncKey = "LastModelParametersSync"
)

// Config is the model pricing configuration.
Expand All @@ -29,3 +22,53 @@ type Config struct {
PricingSyncInterval *int64 `json:"pricing_sync_interval,omitempty"` // seconds
ModelParametersURL *string `json:"model_parameters_url,omitempty"`
}

// Type re-exports so external callers can continue importing the legacy
// names (PricingEntry, PricingOptions, etc.) without changing imports.
// Internally these live in the datasheet / keyconfig subpackages.
type (
PricingEntry = datasheet.Entry
PricingOptions = datasheet.Options
PricingOverride = datasheet.Override
PricingLookupScopes = datasheet.LookupScopes
ScopeKind = datasheet.ScopeKind
MatchType = datasheet.MatchType

KeyConfigEntry = keyconfig.KeyEntry
AliasOwner = keyconfig.AliasOwner
)

// Scope kind constants re-exported for callers that compare by value.
const (
ScopeKindGlobal = datasheet.ScopeKindGlobal
ScopeKindProvider = datasheet.ScopeKindProvider
ScopeKindProviderKey = datasheet.ScopeKindProviderKey
ScopeKindVirtualKey = datasheet.ScopeKindVirtualKey
ScopeKindVirtualKeyProvider = datasheet.ScopeKindVirtualKeyProvider
ScopeKindVirtualKeyProviderKey = datasheet.ScopeKindVirtualKeyProviderKey

MatchTypeExact = datasheet.MatchTypeExact
MatchTypeWildcard = datasheet.MatchTypeWildcard
)

// PricingLookupScopesFromContext is re-exported so callers don't have to
// change their imports.
func PricingLookupScopesFromContext(ctx *schemas.BifrostContext, provider string) *PricingLookupScopes {
return datasheet.LookupScopesFromContext(ctx, provider)
}

// Sync timing defaults re-exported from datasheet for consumers of the
// historical constants.
const (
DefaultPricingURL = datasheet.DefaultURL
DefaultModelParametersURL = datasheet.DefaultModelParametersURL
DefaultPricingTimeout = datasheet.DefaultPricingTimeout
DefaultModelParametersTimeout = datasheet.DefaultModelParametersTimeout
)

// syncWorkerTickerPeriod is the fixed interval at which the background sync worker
// wakes up to check whether a sync is due. This is independent of pricingSyncInterval —
// the ticker defines the check granularity, not the sync frequency.
// Kept well below MinimumPricingSyncIntervalSec so the threshold check is not
// defeated by ticker drift when pricingSyncInterval is set near the minimum.
const syncWorkerTickerPeriod = 5 * time.Minute
Loading
Loading