package llamaswap import ( "context" "fmt" "io" "net/http" "gitea.stevedudenhoeffer.com/steve/majordomo/llm" ) // Health reports whether the llama-swap instance is reachable (GET // {base}/health, which answers "OK" without touching any model). A nil error // means the proxy itself is up — it says nothing about how long a subsequent // request will take (a cold model swap can still block for minutes). Bound // the probe with a short context deadline; the client has no timeout by // design. // // Failure taxonomy matches the rest of the package: transport failures wrap // the raw net error; a reachable-but-unhealthy status comes back as // *llm.APIError, so callers can errors.As-distinguish the two. func (p *Provider) Health(ctx context.Context) error { if err := p.requireBaseURL(); err != nil { return err } req, err := p.newRequest(ctx, http.MethodGet, "/health", "", nil) if err != nil { return err } resp, err := p.client.Do(req) if err != nil { return fmt.Errorf("llama-swap: health probe: %w", err) } defer resp.Body.Close() _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 1<<10)) if resp.StatusCode/100 != 2 { return &llm.APIError{ Provider: p.name, Status: resp.StatusCode, Message: "health endpoint returned a non-2xx status", } } return nil }