diff --git a/internal/llamacpp/health.go b/internal/llamacpp/health.go index c642ccd..12d790f 100644 --- a/internal/llamacpp/health.go +++ b/internal/llamacpp/health.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "net/http" "strings" ) @@ -39,7 +40,8 @@ func (c *Client) Health(ctx context.Context) error { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("llamacpp: health returned %d", resp.StatusCode) + body, _ := io.ReadAll(io.LimitReader(resp.Body, 256)) + return fmt.Errorf("llamacpp: health returned %d: %s", resp.StatusCode, string(body)) } var h healthResponse if err := json.NewDecoder(resp.Body).Decode(&h); err != nil { diff --git a/internal/llamacpp/health_test.go b/internal/llamacpp/health_test.go index 3a3a971..38affcf 100644 --- a/internal/llamacpp/health_test.go +++ b/internal/llamacpp/health_test.go @@ -35,6 +35,19 @@ func TestHealth_NotReady(t *testing.T) { assert.ErrorContains(t, err, "not ready") } +func TestHealth_Loading(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusServiceUnavailable) + w.Write([]byte(`{"error":{"code":503,"message":"Loading model","type":"unavailable_error"}}`)) + })) + defer ts.Close() + + c := NewClient(ts.URL) + err := c.Health(context.Background()) + assert.ErrorContains(t, err, "503") +} + func TestHealth_ServerDown(t *testing.T) { c := NewClient("http://127.0.0.1:1") // nothing listening err := c.Health(context.Background())