cmd: provide feedback if OLLAMA_MODELS is set on non-serve command (#3470)

This also moves the checkServerHeartbeat call out of the "RunE" Cobra
stuff (that's the only word I have for that) to on-site where it's after
the check for OLLAMA_MODELS, which allows the helpful error message to
be printed before the server heartbeat check. This also arguably makes
the code more readable without the magic/superfluous "pre" function
caller.
This commit is contained in:
Blake Mizerany 2024-04-02 22:11:13 -07:00 committed by GitHub
parent 464d817824
commit 7d05a6ee8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -226,6 +226,14 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
}
func RunHandler(cmd *cobra.Command, args []string) error {
if os.Getenv("OLLAMA_MODELS") != "" {
return errors.New("OLLAMA_MODELS must only be set for 'ollama serve'")
}
if err := checkServerHeartbeat(cmd, args); err != nil {
return err
}
client, err := api.ClientFromEnvironment()
if err != nil {
return err
@ -954,7 +962,6 @@ func NewCLI() *cobra.Command {
Use: "run MODEL [PROMPT]",
Short: "Run a model",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: RunHandler,
}