mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-04 01:48:57 +00:00
genconfig writes a "bifrost" key set as a Bifrost config: a custom provider per deployment, a routing rule per model group, virtual keys, and with -features full key/team/customer budgets and rate limits, model configs for deployment limits, the logs store with S3 payloads, the telemetry plugin and header forwarding/stripping/logging. A pricing file copies the cost map's prices per deployment. mockllm answers Bedrock Converse (streamed and not), serves a self-signed TLS listener for Bifrost's HTTPS-only Bedrock provider, and echoes the request's model, which Bifrost prices by. s3stub answers HeadBucket. loadgen takes -chat-path and -messages-path for Bifrost's /anthropic/v1/messages. verify reads a side named bifrost in Bifrost's schema and reports what it has no counterpart for (users, members, daily tables, provider_metadata, cross-replica state) as n/a; with three sides it compares every pair. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XF7rGf49TWYH5Hqkb14eSL
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strings"
|
|
)
|
|
|
|
// compareSides checks that two sides, given identical requests, recorded identical spend, and
|
|
// lists the telemetry one side has and the other lacks. Missing telemetry is reported, not
|
|
// failed: some of it is deliberately left out of one gateway.
|
|
func compareSides(r *report, a, b string, da, db *dbTotals, ma, mb map[string]*family, la, lb *s3Totals) {
|
|
both := a + " vs " + b
|
|
if da != nil && db != nil {
|
|
// Routing picks deployments at random and they are priced differently, so the sides'
|
|
// spend agrees per deployment price, not in total.
|
|
for _, name := range sortedKeys(da.Deployments) {
|
|
pb := db.Deployments[name]
|
|
if pb == nil {
|
|
continue
|
|
}
|
|
inA, outA, okA := da.Deployments[name].prices()
|
|
inB, outB, okB := pb.prices()
|
|
if !okA || !okB {
|
|
continue
|
|
}
|
|
price := func(in, out float64) string {
|
|
return fmt.Sprintf("$%.4f / $%.4f per 1M", in*1e6, out*1e6)
|
|
}
|
|
r.add(check{Name: "input / output price for " + name, Side: both, Want: price(inA, outA),
|
|
Got: price(inB, outB), OK: closeTo(inA, inB) && closeTo(outA, outB)})
|
|
}
|
|
r.add(info("total spend ("+a+" / "+b+")", both, fmt.Sprintf("$%.6f / $%.6f", da.Spend, db.Spend)))
|
|
}
|
|
// Bifrost's metrics and log objects have their own schema; listing their differences from
|
|
// LiteLLM's says nothing, so only LiteLLM sides compare telemetry.
|
|
if isBifrost(a) || isBifrost(b) {
|
|
return
|
|
}
|
|
if ma != nil && mb != nil {
|
|
fa, fb := litellmFamilies(ma), litellmFamilies(mb)
|
|
r.add(info("metrics only on "+a, both, missing(fa, fb)))
|
|
r.add(info("metrics only on "+b, both, missing(fb, fa)))
|
|
var labels []string
|
|
for _, name := range sortedKeys(fa) {
|
|
if f, ok := fb[name]; ok {
|
|
if only := missing(fa[name].labels, f.labels); only != "" {
|
|
labels = append(labels, name+": "+only)
|
|
}
|
|
}
|
|
}
|
|
r.add(info("labels only on "+a+" (shared metrics)", both, strings.Join(labels, "; ")))
|
|
}
|
|
if la != nil && lb != nil {
|
|
r.add(info("S3 log fields only on "+a, both, missing(la.Fields, lb.Fields)))
|
|
r.add(info("S3 log fields only on "+b, both, missing(lb.Fields, la.Fields)))
|
|
r.add(info("S3 log metadata only on "+a, both, missing(la.Metadata, lb.Metadata)))
|
|
r.add(info("S3 log metadata only on "+b, both, missing(lb.Metadata, la.Metadata)))
|
|
}
|
|
}
|
|
|
|
func info(name, side, got string) check {
|
|
if got == "" {
|
|
got = "none"
|
|
}
|
|
return check{Name: name, Side: side, Want: "-", Got: got, OK: true, Note: "reported"}
|
|
}
|
|
|
|
// missing lists the keys of a that b lacks.
|
|
func missing[V any, W any](a map[string]V, b map[string]W) string {
|
|
var out []string
|
|
for _, k := range sortedKeys(a) {
|
|
if _, ok := b[k]; !ok {
|
|
out = append(out, k)
|
|
}
|
|
}
|
|
return strings.Join(out, ", ")
|
|
}
|
|
|
|
// closeTo allows for the float error of fitting prices from summed spend.
|
|
func closeTo(a, b float64) bool {
|
|
return math.Abs(a-b) <= 1e-4*math.Max(math.Abs(a), math.Abs(b))
|
|
}
|