do not pull when local is available

This commit is contained in:
Bruce MacDonald 2023-07-07 10:22:37 -04:00
parent a88576e59a
commit ad84138469

View file

@ -35,8 +35,6 @@ func RunRun(cmd *cobra.Command, args []string) error {
if err := pull(args[0]); err != nil { if err := pull(args[0]); err != nil {
return err return err
} }
fmt.Println("Up to date.")
case err != nil: case err != nil:
return err return err
} }
@ -45,20 +43,27 @@ func RunRun(cmd *cobra.Command, args []string) error {
} }
func pull(model string) error { func pull(model string) error {
client := api.NewClient() // TODO: check if the local model is up to date with remote
_, err := os.Stat(cacheDir() + "/models/" + model + ".bin")
switch {
case errors.Is(err, os.ErrNotExist):
client := api.NewClient()
var bar *progressbar.ProgressBar
return client.Pull(
context.Background(),
&api.PullRequest{Model: model},
func(progress api.PullProgress) error {
if bar == nil {
bar = progressbar.DefaultBytes(progress.Total)
}
var bar *progressbar.ProgressBar return bar.Set64(progress.Completed)
return client.Pull( },
context.Background(), )
&api.PullRequest{Model: model}, case err != nil:
func(progress api.PullProgress) error { return err
if bar == nil { }
bar = progressbar.DefaultBytes(progress.Total) return nil
}
return bar.Set64(progress.Completed)
},
)
} }
func RunGenerate(_ *cobra.Command, args []string) error { func RunGenerate(_ *cobra.Command, args []string) error {