fix(ai): normalize Ollama base URL to prevent 405 errors

Users sometimes enter URLs with trailing slashes or include the /api path:
- http://host:11434/  -> would become http://host:11434//api/chat
- http://host:11434/api -> would become http://host:11434/api/api/chat

Now we strip trailing slashes and /api suffix during client initialization.

Fixes #847
This commit is contained in:
rcourtman 2025-12-15 16:51:52 +00:00
parent 0d2d71b238
commit 71783f8852

View file

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
@ -22,6 +23,11 @@ func NewOllamaClient(model, baseURL string) *OllamaClient {
if baseURL == "" {
baseURL = "http://localhost:11434"
}
// Normalize the URL: strip trailing slashes and /api suffix
// Users sometimes enter http://host:11434/ or http://host:11434/api
baseURL = strings.TrimSuffix(baseURL, "/")
baseURL = strings.TrimSuffix(baseURL, "/api")
baseURL = strings.TrimSuffix(baseURL, "/") // In case it was /api/
return &OllamaClient{
model: model,
baseURL: baseURL,