MCPcopy Create free account
hub / github.com/github/gh-aw / initModelPrices

Function initModelPrices

pkg/cli/model_costs.go:42–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40)
41
42func initModelPrices() {
43 modelPricesOnce.Do(func() {
44 var data modelsCatalogData
45 if err := json.Unmarshal(modelsJSON, &data); err != nil {
46 return
47 }
48
49 modelPriceRecords = make([]modelPriceRecord, 0)
50 for providerName, providerData := range data.Providers {
51 normalizedProvider := strings.ToLower(strings.TrimSpace(providerName))
52 if normalizedProvider == "" { //nolint:tolowerequalfold
53 continue
54 }
55 for modelName, entry := range providerData.Models {
56 normalizedModel := strings.ToLower(strings.TrimSpace(modelName))
57 if normalizedModel == "" { //nolint:tolowerequalfold
58 continue
59 }
60 normalizedID := normalizedProvider + "/" + normalizedModel
61 record := modelPriceRecord{
62 id: normalizedID,
63 provider: normalizedProvider,
64 model: normalizedModel,
65 pricing: make(map[string]float64, len(entry.Cost)),
66 }
67 for key, value := range entry.Cost {
68 if parsed, err := strconv.ParseFloat(strings.TrimSpace(value), 64); err == nil {
69 record.pricing[key] = parsed
70 }
71 }
72 modelPriceRecords = append(modelPriceRecords, record)
73 }
74 }
75 modelCostsLog.Printf("Initialized model price catalog: providers=%d, records=%d", len(data.Providers), len(modelPriceRecords))
76 })
77}
78
79func findModelPricing(provider, model string) (map[string]float64, bool) {
80 initModelPrices()

Callers 1

findModelPricingFunction · 0.85

Calls 2

ToLowerMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected