feat(ollama): improve configuration and dashboard integration
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

This commit is contained in:
2026-04-07 12:53:17 +00:00
parent 1b5cd2815e
commit 1e13b0376b
4 changed files with 197 additions and 7 deletions
+69
View File
@@ -884,6 +884,11 @@ func (s *Server) handleGetProviders(c *gin.Context) {
}
}
// If it's ollama, also include models from config
if id == "ollama" {
models = append(models, s.cfg.Providers.Ollama.Models...)
}
result = append(result, gin.H{
"id": id,
"name": name,
@@ -1012,6 +1017,7 @@ func (s *Server) handleGetModels(c *gin.Context) {
"google": "gemini",
"deepseek": "deepseek",
"xai": "grok",
"ollama": "ollama",
}
// Merge registry models with DB overrides
@@ -1107,6 +1113,69 @@ func (s *Server) handleGetModels(c *gin.Context) {
}
}
// Add configured Ollama models if they aren't in registry
if s.cfg.Providers.Ollama.Enabled {
for _, mID := range s.cfg.Providers.Ollama.Models {
// Check if already added from registry
exists := false
for _, r := range result {
if r["id"] == mID {
exists = true
break
}
}
if exists {
continue
}
if usedOnly && !usedPairs[fmt.Sprintf("%s:ollama", mID)] {
continue
}
enabled := true
promptCost := 0.0
completionCost := 0.0
var cacheReadCost *float64
var cacheWriteCost *float64
var mapping *string
contextLimit := uint32(0)
// Override from DB
if dbCfg, ok := dbMap[mID]; ok {
enabled = dbCfg.Enabled
if dbCfg.PromptCostPerM != nil {
promptCost = *dbCfg.PromptCostPerM
}
if dbCfg.CompletionCostPerM != nil {
completionCost = *dbCfg.CompletionCostPerM
}
if dbCfg.CacheReadCostPerM != nil {
cacheReadCost = dbCfg.CacheReadCostPerM
}
if dbCfg.CacheWriteCostPerM != nil {
cacheWriteCost = dbCfg.CacheWriteCostPerM
}
mapping = dbCfg.Mapping
}
result = append(result, gin.H{
"id": mID,
"name": mID,
"provider": "ollama",
"enabled": enabled,
"prompt_cost": promptCost,
"completion_cost": completionCost,
"cache_read_cost": cacheReadCost,
"cache_write_cost": cacheWriteCost,
"context_limit": contextLimit,
"modalities": gin.H{"input": []string{"text"}, "output": []string{"text"}},
"tool_call": false,
"reasoning": false,
"mapping": mapping,
})
}
}
c.JSON(http.StatusOK, SuccessResponse(result))
}