TestConnection tests the AI connection (admin only).
(w http.ResponseWriter, r *http.Request)
| 205 | |
| 206 | // TestConnection tests the AI connection (admin only). |
| 207 | func (h *AIHandler) TestConnection(w http.ResponseWriter, r *http.Request) { |
| 208 | s, err := h.settings.GetFirst(r.Context()) |
| 209 | if err != nil { |
| 210 | Error(w, http.StatusInternalServerError, "Failed to load settings") |
| 211 | return |
| 212 | } |
| 213 | if s.AiAPIKey == nil || *s.AiAPIKey == "" { |
| 214 | Error(w, http.StatusBadRequest, "AI API key not configured") |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | response, err := h.aiSvc.GetAssistance(s, "Respond with exactly: 'Connection successful!' - nothing else.", "", nil) |
| 219 | if err != nil { |
| 220 | Error(w, http.StatusBadRequest, "Connection test failed: "+err.Error()) |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | if strings.Contains(strings.ToLower(response), "connection successful") { |
| 225 | JSON(w, http.StatusOK, map[string]interface{}{"success": true, "message": "AI connection test successful"}) |
| 226 | return |
| 227 | } |
| 228 | JSON(w, http.StatusOK, map[string]interface{}{ |
| 229 | "success": true, |
| 230 | "message": "AI responded", |
| 231 | "response": response, |
| 232 | }) |
| 233 | } |
| 234 | |
| 235 | // AssistRequest is the body for POST /ai/assist. |
| 236 | type AssistRequest struct { |
nothing calls this directly
no test coverage detected