From d896e53c08277a4ee28da19cead2766a9039cd6c Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 28 Oct 2025 20:53:43 -0700 Subject: [PATCH] remove --- api/client.go | 8 -------- cmd/cmd.go | 38 +------------------------------------- cmd/remove.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 45 deletions(-) create mode 100644 cmd/remove.go diff --git a/api/client.go b/api/client.go index 9bab4462e..319664f87 100644 --- a/api/client.go +++ b/api/client.go @@ -351,14 +351,6 @@ func (c *Client) Copy(ctx context.Context, req *CopyRequest) error { return nil } -// Delete deletes a model and its data. -func (c *Client) Delete(ctx context.Context, req *DeleteRequest) error { - if err := c.do(ctx, http.MethodDelete, "/api/delete", req, nil); err != nil { - return err - } - return nil -} - // Show obtains model information, including details, modelfile, license etc. func (c *Client) Show(ctx context.Context, req *ShowRequest) (*ShowResponse, error) { var resp ShowResponse diff --git a/cmd/cmd.go b/cmd/cmd.go index 86e4d9f3b..74c3078ee 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -676,33 +676,6 @@ func ListRunningHandler(cmd *cobra.Command, args []string) error { return nil } -func DeleteHandler(cmd *cobra.Command, args []string) error { - client, err := api.ClientFromEnvironment() - if err != nil { - return err - } - - // Unload the model if it's running before deletion - opts := &runOptions{ - Model: args[0], - KeepAlive: &api.Duration{Duration: 0}, - } - if err := loadOrUnloadModel(cmd, opts); err != nil { - if !strings.Contains(strings.ToLower(err.Error()), "not found") { - fmt.Fprintf(os.Stderr, "Warning: unable to stop model '%s'\n", args[0]) - } - } - - for _, name := range args { - req := api.DeleteRequest{Name: name} - if err := client.Delete(cmd.Context(), &req); err != nil { - return err - } - fmt.Printf("deleted '%s'\n", name) - } - return nil -} - func ShowHandler(cmd *cobra.Command, args []string) error { client, err := api.ClientFromEnvironment() if err != nil { @@ -1652,14 +1625,6 @@ func NewCLI() *cobra.Command { RunE: CopyHandler, } - deleteCmd := &cobra.Command{ - Use: "rm MODEL [MODEL...]", - Short: "Remove a model", - Args: cobra.MinimumNArgs(1), - PreRunE: checkServerHeartbeat, - RunE: DeleteHandler, - } - runnerCmd := &cobra.Command{ Use: "runner", Hidden: true, @@ -1684,7 +1649,6 @@ func NewCLI() *cobra.Command { pushCmd, psCmd, copyCmd, - deleteCmd, serveCmd, } { switch cmd { @@ -1727,7 +1691,7 @@ func NewCLI() *cobra.Command { cmdList(), psCmd, copyCmd, - deleteCmd, + cmdRemove(), runnerCmd, ) diff --git a/cmd/remove.go b/cmd/remove.go new file mode 100644 index 000000000..5017147ed --- /dev/null +++ b/cmd/remove.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "fmt" + + "github.com/ollama/ollama/api" + "github.com/ollama/ollama/client" + "github.com/spf13/cobra" +) + +func cmdRemove() *cobra.Command { + return &cobra.Command{ + Use: "remove [model]...", + Aliases: []string{"rm"}, + Short: "Remove one or more models from the local repository", + Args: cobra.MinimumNArgs(1), + PreRunE: checkServerHeartbeat, + RunE: removeHandler, + } +} + +func removeHandler(cmd *cobra.Command, args []string) error { + c := client.New() + for _, arg := range args { + // TODO: stop model if it's running; skip if model is cloud + if err := c.Delete(cmd.Context(), api.DeleteRequest{Model: arg}); err != nil { + return err + } + fmt.Println("deleted", arg) + } + return nil +}