Skip to content
Open
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
27 changes: 27 additions & 0 deletions apps/manager-server/internal/service/modelprice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (s *Service) Sync(ctx context.Context, req SyncRequest) (SyncResult, error)
if err != nil {
return SyncResult{}, err
}
selection = filterSelectionFeedback(selection, prices)
return SyncResult{
Source: syncResultSource(sources),
Sources: sources,
Expand Down Expand Up @@ -824,3 +825,29 @@ func readString(entry map[string]any, key string) string {
return ""
}
}

// filterSelectionFeedback drops candidate and unmatched entries for models that
// already have a stored price. Sync feedback should only report models the user
// can still act on; the prices page intentionally hides priced rows from the
// pending-confirmation filter to protect manually configured prices, so reporting
// them here only produces misleading counts.
func filterSelectionFeedback(selection priceSelectionResult, prices map[string]store.ModelPrice) priceSelectionResult {
if len(selection.Candidates) == 0 && len(selection.Unmatched) == 0 {
return selection
}
candidates := make([]SyncCandidateSet, 0, len(selection.Candidates))
for _, set := range selection.Candidates {
if _, priced := prices[set.Model]; !priced {
candidates = append(candidates, set)
}
}
unmatched := make([]string, 0, len(selection.Unmatched))
for _, model := range selection.Unmatched {
if _, priced := prices[model]; !priced {
unmatched = append(unmatched, model)
}
}
selection.Candidates = candidates
selection.Unmatched = unmatched
return selection
}
50 changes: 50 additions & 0 deletions apps/manager-server/internal/service/modelprice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,53 @@ func closePrice(left float64, right float64) bool {
}
return right-left < 0.0000001
}

func TestFilterSelectionFeedbackDropsPricedModels(t *testing.T) {
selection := priceSelectionResult{
Prices: map[string]store.ModelPrice{},
Matched: map[string]store.ModelPrice{},
Candidates: []SyncCandidateSet{
{
Model: "priced-ambiguous",
Candidates: []SyncCandidate{
{SourceModelID: "vendor/priced-ambiguous", Score: 0.9, Price: store.ModelPrice{Prompt: 1, Completion: 2}},
},
},
{
Model: "unpriced-ambiguous",
Candidates: []SyncCandidate{
{SourceModelID: "vendor/unpriced-ambiguous", Score: 0.9, Price: store.ModelPrice{Prompt: 3, Completion: 4}},
},
},
},
Unmatched: []string{"priced-unmatched", "unpriced-unmatched"},
}
stored := map[string]store.ModelPrice{
"priced-ambiguous": {Prompt: 5, Completion: 6},
"priced-unmatched": {Prompt: 7, Completion: 8},
}

filtered := filterSelectionFeedback(selection, stored)

if len(filtered.Candidates) != 1 || filtered.Candidates[0].Model != "unpriced-ambiguous" {
t.Fatalf("candidates = %#v", filtered.Candidates)
}
if len(filtered.Unmatched) != 1 || filtered.Unmatched[0] != "unpriced-unmatched" {
t.Fatalf("unmatched = %#v", filtered.Unmatched)
}
}

func TestFilterSelectionFeedbackKeepsEverythingWithoutStoredPrices(t *testing.T) {
selection := priceSelectionResult{
Candidates: []SyncCandidateSet{
{Model: "unpriced-ambiguous", Candidates: []SyncCandidate{{SourceModelID: "vendor/x", Score: 0.9}}},
},
Unmatched: []string{"unpriced-unmatched"},
}

filtered := filterSelectionFeedback(selection, nil)

if len(filtered.Candidates) != 1 || len(filtered.Unmatched) != 1 {
t.Fatalf("filtered = %#v", filtered)
}
}
Loading