Commit 3ca56b5a authored by Michael Yang's avatar Michael Yang
Browse files

add create modelfile field

parent b0d14ed5
...@@ -101,6 +101,7 @@ type EmbeddingResponse struct { ...@@ -101,6 +101,7 @@ type EmbeddingResponse struct {
type CreateRequest struct { type CreateRequest struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
Modelfile string `json:"modelfile"`
Stream *bool `json:"stream,omitempty"` Stream *bool `json:"stream,omitempty"`
} }
......
...@@ -410,17 +410,27 @@ func CreateModelHandler(c *gin.Context) { ...@@ -410,17 +410,27 @@ func CreateModelHandler(c *gin.Context) {
return return
} }
if req.Name == "" || req.Path == "" { if req.Name == "" {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name and path are required"}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
return
}
if req.Path == "" && req.Modelfile == "" {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "path or modelfile are required"})
return return
} }
modelfile, err := os.Open(req.Path) var modelfile io.Reader = strings.NewReader(req.Modelfile)
if req.Path != "" && req.Modelfile == "" {
bin, err := os.Open(req.Path)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("error reading modelfile: %s", err)})
return return
} }
defer modelfile.Close() defer bin.Close()
modelfile = bin
}
commands, err := parser.Parse(modelfile) commands, err := parser.Parse(modelfile)
if err != nil { if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment