feat(ollama): improve configuration and dashboard integration
This commit is contained in:
@@ -154,6 +154,7 @@ func (s *Server) RefreshProviders() error {
|
||||
s.providers["grok"] = providers.NewGrokProvider(cfg, apiKey)
|
||||
case "ollama":
|
||||
cfg := s.cfg.Providers.Ollama
|
||||
fmt.Printf("[DEBUG] Ollama config: Enabled=%v, BaseURL=%s, Models=%v\n", cfg.Enabled, baseURL, cfg.Models)
|
||||
cfg.BaseURL = baseURL
|
||||
s.providers["ollama"] = providers.NewOllamaProvider(cfg)
|
||||
}
|
||||
@@ -271,6 +272,28 @@ func (s *Server) handleListModels(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add configured Ollama models
|
||||
if s.cfg.Providers.Ollama.Enabled {
|
||||
for _, mID := range s.cfg.Providers.Ollama.Models {
|
||||
// Check if already added
|
||||
exists := false
|
||||
for _, d := range data {
|
||||
if d.ID == mID {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
data = append(data, OpenAIModel{
|
||||
ID: mID,
|
||||
Object: "model",
|
||||
Created: 1700000000,
|
||||
OwnedBy: "ollama",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"object": "list",
|
||||
"data": data,
|
||||
@@ -305,9 +328,17 @@ func (s *Server) handleChatCompletions(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Strip common prefixes
|
||||
modelID := req.Model
|
||||
if strings.HasPrefix(modelID, "gemini/") {
|
||||
modelID = strings.TrimPrefix(modelID, "gemini/")
|
||||
} else if strings.HasPrefix(modelID, "google/") {
|
||||
modelID = strings.TrimPrefix(modelID, "google/")
|
||||
}
|
||||
|
||||
// Convert ChatCompletionRequest to UnifiedRequest
|
||||
unifiedReq := &models.UnifiedRequest{
|
||||
Model: req.Model,
|
||||
Model: modelID,
|
||||
Messages: []models.UnifiedMessage{},
|
||||
Temperature: req.Temperature,
|
||||
TopP: req.TopP,
|
||||
|
||||
Reference in New Issue
Block a user