Skip to content

Commit 7ca71a6

Browse files
authored
don't abort when an invalid model name is used in /save (ollama#4416)
1 parent 7607e6e commit 7ca71a6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

cmd/interactive.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ollama/ollama/api"
1818
"github.com/ollama/ollama/progress"
1919
"github.com/ollama/ollama/readline"
20+
"github.com/ollama/ollama/types/errtypes"
2021
)
2122

2223
type MultilineState int
@@ -281,7 +282,10 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
281282
fn := func(resp api.ProgressResponse) error { return nil }
282283
err = client.Create(cmd.Context(), req, fn)
283284
if err != nil {
284-
fmt.Println("error: couldn't save model")
285+
if strings.Contains(err.Error(), errtypes.InvalidModelNameErrMsg) {
286+
fmt.Printf("error: The model name '%s' is invalid\n", args[1])
287+
continue
288+
}
285289
return err
286290
}
287291
fmt.Printf("Created new model '%s'\n", args[1])

server/routes.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ollama/ollama/llm"
3131
"github.com/ollama/ollama/openai"
3232
"github.com/ollama/ollama/server/envconfig"
33+
"github.com/ollama/ollama/types/errtypes"
3334
"github.com/ollama/ollama/types/model"
3435
"github.com/ollama/ollama/version"
3536
)
@@ -517,7 +518,7 @@ func (s *Server) CreateModelHandler(c *gin.Context) {
517518

518519
name := model.ParseName(cmp.Or(req.Model, req.Name))
519520
if !name.IsValid() {
520-
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "invalid model name"})
521+
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": errtypes.InvalidModelNameErrMsg})
521522
return
522523
}
523524

types/errtypes/errtypes.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
const UnknownOllamaKeyErrMsg = "unknown ollama key"
10+
const InvalidModelNameErrMsg = "invalid model name"
1011

1112
// TODO: This should have a structured response from the API
1213
type UnknownOllamaKey struct {

0 commit comments

Comments
 (0)