From a3df9580321dd8796c4dc5a0dfea46487fbb0770 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 28 Oct 2025 20:55:22 -0700 Subject: [PATCH] version --- api/client.go | 13 ------------- client/client.go | 5 ++--- cmd/cmd.go | 8 ++------ 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/api/client.go b/api/client.go index 0d4c97ba9..cb7dd885a 100644 --- a/api/client.go +++ b/api/client.go @@ -429,19 +429,6 @@ func (c *Client) CreateBlob(ctx context.Context, digest string, r io.Reader) err return c.do(ctx, http.MethodPost, fmt.Sprintf("/api/blobs/%s", digest), r, nil) } -// Version returns the Ollama server version as a string. -func (c *Client) Version(ctx context.Context) (string, error) { - var version struct { - Version string `json:"version"` - } - - if err := c.do(ctx, http.MethodGet, "/api/version", nil, &version); err != nil { - return "", err - } - - return version.Version, nil -} - // Signout will signout a client for a local ollama server. func (c *Client) Signout(ctx context.Context) error { return c.do(ctx, http.MethodPost, "/api/signout", nil, nil) diff --git a/client/client.go b/client/client.go index 231aad239..bc23a724f 100644 --- a/client/client.go +++ b/client/client.go @@ -100,10 +100,9 @@ func (c *Client) Delete(ctx context.Context, r api.DeleteRequest) error { // Version returns the Ollama server version. func (c *Client) Version(ctx context.Context) (string, error) { - type versionResponse struct { + version, err := do[struct { Version string `json:"version"` - } - version, err := do[versionResponse](c, ctx, "GET", "/api/version", nil) + }](c, ctx, "GET", "/api/version", nil) if err != nil { return "", err } diff --git a/cmd/cmd.go b/cmd/cmd.go index 369a27a48..e07ce2665 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -35,6 +35,7 @@ import ( "golang.org/x/term" "github.com/ollama/ollama/api" + "github.com/ollama/ollama/client" "github.com/ollama/ollama/envconfig" "github.com/ollama/ollama/format" "github.com/ollama/ollama/parser" @@ -1575,12 +1576,7 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error { } func versionHandler(cmd *cobra.Command, _ []string) { - client, err := api.ClientFromEnvironment() - if err != nil { - return - } - - serverVersion, err := client.Version(cmd.Context()) + serverVersion, err := client.New().Version(cmd.Context()) if err != nil { fmt.Println("Warning: could not connect to a running Ollama instance") }