only replace if it matches command

This commit is contained in:
Michael Yang 2024-04-24 14:27:12 -07:00
parent ad66e5b060
commit ac0801eced

View file

@ -17,6 +17,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"strings" "strings"
"syscall" "syscall"
@ -110,7 +111,13 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
return err return err
} }
modelfile = bytes.ReplaceAll(modelfile, []byte(c.Args), []byte("@"+digest)) name := c.Name
if c.Name == "model" {
name = "from"
}
re := regexp.MustCompile(fmt.Sprintf(`(?im)^(%s)\s+%s\s*$`, name, c.Args))
modelfile = re.ReplaceAll(modelfile, []byte("$1 @"+digest))
} }
} }