Skip to content

Commit

Permalink
clean up: remove server functions from client (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceMacD committed Oct 30, 2023
1 parent 8d03bd7 commit f9a4281
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
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

0 comments on commit f9a4281

Please sign in to comment.