validate existence and pull model using api

This commit is contained in:
Michael Yang 2023-09-21 09:50:52 -07:00
parent 1fabba474b
commit 6137b12799

View file

@ -11,7 +11,6 @@ import (
"io" "io"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -108,35 +107,28 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
} }
func RunHandler(cmd *cobra.Command, args []string) error { func RunHandler(cmd *cobra.Command, args []string) error {
insecure, err := cmd.Flags().GetBool("insecure") client, err := api.FromEnv()
if err != nil { if err != nil {
return err return err
} }
mp := server.ParseModelPath(args[0]) models, err := client.List(context.Background())
if mp.ProtocolScheme == "http" && !insecure {
return fmt.Errorf("insecure protocol http")
}
fp, err := mp.GetManifestPath(false)
if err != nil { if err != nil {
return err return err
} }
_, err = os.Stat(fp) modelName, modelTag, ok := strings.Cut(args[0], ":")
switch { if !ok {
case errors.Is(err, os.ErrNotExist): modelTag = "latest"
if err := pull(args[0], insecure); err != nil {
var apiStatusError api.StatusError
if !errors.As(err, &apiStatusError) {
return err
} }
if apiStatusError.StatusCode != http.StatusBadGateway { for _, model := range models.Models {
return err if model.Name == strings.Join([]string{modelName, modelTag}, ":") {
return RunGenerate(cmd, args)
} }
} }
case err != nil:
if err := PullHandler(cmd, args); err != nil {
return err return err
} }