Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

don't abort when an invalid model name is used in /save (#4416)

Patrick Devine7ca71a6b0fd4
diff --git a/cmd/interactive.go b/cmd/interactive.go
index 21c0a6a93..c078650ab 100644
--- a/cmd/interactive.go
+++ b/cmd/interactive.go
@@ -17,6 +17,7 @@ import (
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/progress"
"github.com/ollama/ollama/readline"
+ "github.com/ollama/ollama/types/errtypes"
)
type MultilineState int
@@ -281,7 +282,10 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
fn := func(resp api.ProgressResponse) error { return nil }
err = client.Create(cmd.Context(), req, fn)
if err != nil {
- fmt.Println("error: couldn't save model")
+ if strings.Contains(err.Error(), errtypes.InvalidModelNameErrMsg) {
+ fmt.Printf("error: The model name '%s' is invalid\n", args[1])
+ continue
+ }
return err
}
fmt.Printf("Created new model '%s'\n", args[1])
diff --git a/server/routes.go b/server/routes.go
index d60a4d08e..aaa461c2e 100644
--- a/server/routes.go
+++ b/server/routes.go
@@ -30,6 +30,7 @@ import (
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/openai"
"github.com/ollama/ollama/server/envconfig"
+ "github.com/ollama/ollama/types/errtypes"
"github.com/ollama/ollama/types/model"
"github.com/ollama/ollama/version"
)
@@ -517,7 +518,7 @@ func (s *Server) CreateModelHandler(c *gin.Context) {
name := model.ParseName(cmp.Or(req.Model, req.Name))
if !name.IsValid() {
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "invalid model name"})
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": errtypes.InvalidModelNameErrMsg})
return
}
diff --git a/types/errtypes/errtypes.go b/types/errtypes/errtypes.go
index e3a18d0b1..d30731140 100644
--- a/types/errtypes/errtypes.go
+++ b/types/errtypes/errtypes.go
@@ -7,6 +7,7 @@ import (
)
const UnknownOllamaKeyErrMsg = "unknown ollama key"
+const InvalidModelNameErrMsg = "invalid model name"
// TODO: This should have a structured response from the API
type UnknownOllamaKey struct {