Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Pass keep_alive=30s to Ollama requests
rcourtman01ea5ebb6e67
diff --git a/internal/ai/providers/ollama.go b/internal/ai/providers/ollama.goindex 7bde1b2a22..3638e3dfc5 100644--- a/internal/ai/providers/ollama.go+++ b/internal/ai/providers/ollama.go@@ -105,8 +105,24 @@ type ollamaRequest struct {Stream bool `json:"stream"`Options *ollamaOptions `json:"options,omitempty"`Tools []ollamaTool `json:"tools,omitempty"` // Tool definitions for function calling+ // KeepAlive controls how long Ollama keeps the model loaded after the+ // request completes. Ollama's default is 5 minutes; without this field+ // every Pulse Chat call refreshes that 5-minute window, so a single+ // call from Patrol or alert analysis can keep the model warm in RAM+ // indefinitely if any other Ollama traffic happens within 5 minutes+ // (#1425). Pulse passes a short value so the model unloads shortly+ // after a Patrol burst or one-shot analysis ends. Accepts duration+ // strings like "30s", "5m", or "0" for immediate unload.+ KeepAlive string `json:"keep_alive,omitempty"`}+// ollamaKeepAlive is the duration Pulse asks Ollama to keep the model loaded+// after a request completes. 30s is short enough that the model unloads+// soon after a Patrol/alert-analysis burst ends, while still long enough+// to span the small gaps between sequential calls in a single analysis+// session so the model isn't reloaded mid-burst.+const ollamaKeepAlive = "30s"+type ollamaMessage struct {Role string `json:"role"`Content string `json:"content"`@@ -212,9 +228,10 @@ func (c *OllamaClient) Chat(ctx context.Context, req ChatRequest) (*ChatResponse}ollamaReq := ollamaRequest{- Model: model,- Messages: messages,- Stream: false, // Non-streaming for now+ Model: model,+ Messages: messages,+ Stream: false, // Non-streaming for now+ KeepAlive: ollamaKeepAlive,}// Convert tools to Ollama format@@ -381,9 +398,10 @@ func (c *OllamaClient) ChatStream(ctx context.Context, req ChatRequest, callback}ollamaReq := ollamaRequest{- Model: model,- Messages: messages,- Stream: true, // Enable streaming+ Model: model,+ Messages: messages,+ Stream: true, // Enable streaming+ KeepAlive: ollamaKeepAlive,}// Handle tools with tool_choice support (same as non-streaming)diff --git a/internal/ai/providers/ollama_test.go b/internal/ai/providers/ollama_test.goindex c938dc801e..035e945bb5 100644--- a/internal/ai/providers/ollama_test.go+++ b/internal/ai/providers/ollama_test.go@@ -36,6 +36,10 @@ func TestOllamaClient_ChatStream_Success(t *testing.T) {assert.True(t, req.Stream)assert.Equal(t, "llama3", req.Model)assert.NotEmpty(t, req.Messages)+ // #1425: Pulse must pass keep_alive so the model unloads shortly+ // after the request burst ends instead of refreshing Ollama's+ // 5-minute default TTL on every call.+ assert.Equal(t, ollamaKeepAlive, req.KeepAlive)w.Header().Set("Content-Type", "application/x-ndjson")w.WriteHeader(http.StatusOK)@@ -180,6 +184,8 @@ func TestOllamaClient_Chat_Success(t *testing.T) {require.NoError(t, json.NewDecoder(r.Body).Decode(&req))assert.False(t, req.Stream)assert.Equal(t, "llama3", req.Model)+ // #1425: keep_alive must be set on non-streaming Chat too.+ assert.Equal(t, ollamaKeepAlive, req.KeepAlive)require.Len(t, req.Tools, 1)assert.Equal(t, "function", req.Tools[0].Type)assert.Equal(t, "get_time", req.Tools[0].Function.Name)