Skip to content

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

add create modelfile field

Michael Yang3ca56b5adafb
diff --git a/api/types.go b/api/types.go
index ffa5b7ca2..2a36a1f62 100644
--- a/api/types.go
+++ b/api/types.go
@@ -99,9 +99,10 @@ type EmbeddingResponse struct {
}
type CreateRequest struct {
- Name string `json:"name"`
- Path string `json:"path"`
- Stream *bool `json:"stream,omitempty"`
+ Name string `json:"name"`
+ Path string `json:"path"`
+ Modelfile string `json:"modelfile"`
+ Stream *bool `json:"stream,omitempty"`
}
type DeleteRequest struct {
diff --git a/server/routes.go b/server/routes.go
index e53bad436..65a969119 100644
--- a/server/routes.go
+++ b/server/routes.go
@@ -410,17 +410,27 @@ func CreateModelHandler(c *gin.Context) {
return
}
- if req.Name == "" || req.Path == "" {
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name and path are required"})
+ if req.Name == "" {
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
return
}
- modelfile, err := os.Open(req.Path)
- if err != nil {
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ if req.Path == "" && req.Modelfile == "" {
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "path or modelfile are required"})
return
}
- defer modelfile.Close()
+
+ var modelfile io.Reader = strings.NewReader(req.Modelfile)
+ if req.Path != "" && req.Modelfile == "" {
+ bin, err := os.Open(req.Path)
+ if err != nil {
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("error reading modelfile: %s", err)})
+ return
+ }
+ defer bin.Close()
+
+ modelfile = bin
+ }
commands, err := parser.Parse(modelfile)
if err != nil {