Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up: remove server functions from client #937

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"log"
"net"
"net/http"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -98,22 +99,21 @@ func RunHandler(cmd *cobra.Command, args []string) error {
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 {
return err
}

canonicalModelPath := server.ParseModelPath(args[0])
for _, model := range models.Models {
if model.Name == canonicalModelPath.GetShortTagname() {
return RunGenerate(cmd, args)
var statusError api.StatusError
switch {
case errors.As(err, &statusError) && statusError.StatusCode == http.StatusNotFound:
if err := PullHandler(cmd, args); err != nil {
return err
}
case err != nil:
return err
}
}

if err := PullHandler(cmd, args); err != nil {
return err
}

return RunGenerate(cmd, args)
}

Expand Down Expand Up @@ -731,21 +731,6 @@ func RunServer(cmd *cobra.Command, _ []string) error {
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)
}

Expand Down
16 changes: 16 additions & 0 deletions server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,22 @@ var defaultAllowOrigins = []string{
}

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.AllowWildcard = true

Expand Down