remove
This commit is contained in:
parent
9bee2450e9
commit
d896e53c08
|
|
@ -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
|
||||
|
|
|
|||
38
cmd/cmd.go
38
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,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue