fix: restrict Model Pricing table to core providers and actual usage
Filtered registry iteration to only include openai, gemini, deepseek, and grok. Improved used_only logic to match specific (model, provider) pairs from logs.
This commit is contained in:
@@ -954,9 +954,12 @@ func (s *Server) handleTestProvider(c *gin.Context) {
|
|||||||
func (s *Server) handleGetModels(c *gin.Context) {
|
func (s *Server) handleGetModels(c *gin.Context) {
|
||||||
usedOnly := c.Query("used_only") == "true"
|
usedOnly := c.Query("used_only") == "true"
|
||||||
|
|
||||||
// Provider name mapping (Registry -> Proxy)
|
// Registry provider normalized name -> Proxy-internal provider ID
|
||||||
providerMap := map[string]string{
|
// This ensures we only show models from YOUR providers.
|
||||||
|
allowedRegistryProviders := map[string]string{
|
||||||
|
"openai": "openai",
|
||||||
"google": "gemini",
|
"google": "gemini",
|
||||||
|
"deepseek": "deepseek",
|
||||||
"xai": "grok",
|
"xai": "grok",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,33 +972,35 @@ func (s *Server) handleGetModels(c *gin.Context) {
|
|||||||
dbMap[m.ID] = m
|
dbMap[m.ID] = m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch set of used model IDs if requested
|
// Fetch specific (model, provider) combinations that have been used
|
||||||
usedModels := make(map[string]bool)
|
type modelProvider struct {
|
||||||
|
Model string `db:"model"`
|
||||||
|
Provider string `db:"provider"`
|
||||||
|
}
|
||||||
|
usedPairs := make(map[string]bool)
|
||||||
if usedOnly {
|
if usedOnly {
|
||||||
rows, err := s.database.Queryx("SELECT DISTINCT model FROM llm_requests")
|
var pairs []modelProvider
|
||||||
|
err := s.database.Select(&pairs, "SELECT DISTINCT model, provider FROM llm_requests WHERE status = 'success'")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for rows.Next() {
|
for _, p := range pairs {
|
||||||
var mID string
|
// Key format: "gpt-4o:openai"
|
||||||
if err := rows.Scan(&mID); err == nil {
|
usedPairs[fmt.Sprintf("%s:%s", p.Model, p.Provider)] = true
|
||||||
usedModels[mID] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rows.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var result []gin.H
|
var result []gin.H
|
||||||
if s.registry != nil {
|
if s.registry != nil {
|
||||||
for pID, pInfo := range s.registry.Providers {
|
for pID, pInfo := range s.registry.Providers {
|
||||||
// Normalize provider name for UI
|
// Only include models from the 4 allowed registry IDs
|
||||||
uiProvider := pID
|
proxyProvider, allowed := allowedRegistryProviders[pID]
|
||||||
if mapped, ok := providerMap[pID]; ok {
|
if !allowed {
|
||||||
uiProvider = mapped
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for mID, mMeta := range pInfo.Models {
|
for mID, mMeta := range pInfo.Models {
|
||||||
// Filter if used_only requested
|
// If usedOnly is true, only include if this exact (model, provider) was logged
|
||||||
if usedOnly && !usedModels[mID] {
|
if usedOnly && !usedPairs[fmt.Sprintf("%s:%s", mID, proxyProvider)] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1038,7 +1043,7 @@ func (s *Server) handleGetModels(c *gin.Context) {
|
|||||||
result = append(result, gin.H{
|
result = append(result, gin.H{
|
||||||
"id": mID,
|
"id": mID,
|
||||||
"name": mMeta.Name,
|
"name": mMeta.Name,
|
||||||
"provider": uiProvider,
|
"provider": proxyProvider, // Correctly normalized provider name
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"prompt_cost": promptCost,
|
"prompt_cost": promptCost,
|
||||||
"completion_cost": completionCost,
|
"completion_cost": completionCost,
|
||||||
|
|||||||
Reference in New Issue
Block a user