clean up: remove server functions from client (#937)

This commit is contained in:
Bruce MacDonald 2023-10-30 11:10:18 -04:00 committed by GitHub
parent 8d03bd7b54
commit f9a4281124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 27 deletions

View file

@ -11,6 +11,7 @@ import (
"io" "io"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
@ -98,21 +99,20 @@ func RunHandler(cmd *cobra.Command, args []string) error {
return err return err
} }
models, err := client.List(context.Background()) name := args[0]
// check if the model exists on the server
_, err = client.Show(context.Background(), &api.ShowRequest{Name: name})
if err != nil { if err != nil {
return err var statusError api.StatusError
} switch {
case errors.As(err, &statusError) && statusError.StatusCode == http.StatusNotFound:
canonicalModelPath := server.ParseModelPath(args[0])
for _, model := range models.Models {
if model.Name == canonicalModelPath.GetShortTagname() {
return RunGenerate(cmd, args)
}
}
if err := PullHandler(cmd, args); err != nil { if err := PullHandler(cmd, args); err != nil {
return err return err
} }
case err != nil:
return err
}
}
return RunGenerate(cmd, args) return RunGenerate(cmd, args)
} }
@ -731,21 +731,6 @@ func RunServer(cmd *cobra.Command, _ []string) error {
origins = strings.Split(o, ",") origins = strings.Split(o, ",")
} }
if noprune := os.Getenv("OLLAMA_NOPRUNE"); noprune == "" {
if err := server.PruneLayers(); err != nil {
return err
}
manifestsPath, err := server.GetManifestPath()
if err != nil {
return err
}
if err := server.PruneDirectory(manifestsPath); err != nil {
return err
}
}
return server.Serve(ln, origins) return server.Serve(ln, origins)
} }

View file

@ -614,6 +614,22 @@ var defaultAllowOrigins = []string{
} }
func Serve(ln net.Listener, allowOrigins []string) error { func Serve(ln net.Listener, allowOrigins []string) error {
if noprune := os.Getenv("OLLAMA_NOPRUNE"); noprune == "" {
// clean up unused layers and manifests
if err := PruneLayers(); err != nil {
return err
}
manifestsPath, err := GetManifestPath()
if err != nil {
return err
}
if err := PruneDirectory(manifestsPath); err != nil {
return err
}
}
config := cors.DefaultConfig() config := cors.DefaultConfig()
config.AllowWildcard = true config.AllowWildcard = true