|
@@ -137,8 +137,13 @@ func GenerateHandler(c *gin.Context) {
|
|
checkpointStart := time.Now()
|
|
checkpointStart := time.Now()
|
|
|
|
|
|
var req api.GenerateRequest
|
|
var req api.GenerateRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -232,8 +237,13 @@ func EmbeddingHandler(c *gin.Context) {
|
|
defer loaded.mu.Unlock()
|
|
defer loaded.mu.Unlock()
|
|
|
|
|
|
var req api.EmbeddingRequest
|
|
var req api.EmbeddingRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -274,8 +284,13 @@ func EmbeddingHandler(c *gin.Context) {
|
|
|
|
|
|
func PullModelHandler(c *gin.Context) {
|
|
func PullModelHandler(c *gin.Context) {
|
|
var req api.PullRequest
|
|
var req api.PullRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -313,8 +328,13 @@ func PullModelHandler(c *gin.Context) {
|
|
|
|
|
|
func PushModelHandler(c *gin.Context) {
|
|
func PushModelHandler(c *gin.Context) {
|
|
var req api.PushRequest
|
|
var req api.PushRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -350,8 +370,13 @@ func PushModelHandler(c *gin.Context) {
|
|
|
|
|
|
func CreateModelHandler(c *gin.Context) {
|
|
func CreateModelHandler(c *gin.Context) {
|
|
var req api.CreateRequest
|
|
var req api.CreateRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -385,8 +410,13 @@ func CreateModelHandler(c *gin.Context) {
|
|
|
|
|
|
func DeleteModelHandler(c *gin.Context) {
|
|
func DeleteModelHandler(c *gin.Context) {
|
|
var req api.DeleteRequest
|
|
var req api.DeleteRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -420,8 +450,13 @@ func DeleteModelHandler(c *gin.Context) {
|
|
|
|
|
|
func ShowModelHandler(c *gin.Context) {
|
|
func ShowModelHandler(c *gin.Context) {
|
|
var req api.ShowRequest
|
|
var req api.ShowRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -536,8 +571,13 @@ func ListModelsHandler(c *gin.Context) {
|
|
|
|
|
|
func CopyModelHandler(c *gin.Context) {
|
|
func CopyModelHandler(c *gin.Context) {
|
|
var req api.CopyRequest
|
|
var req api.CopyRequest
|
|
- if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
|
+ err := c.ShouldBindJSON(&req)
|
|
|
|
+ switch {
|
|
|
|
+ case errors.Is(err, io.EOF):
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "missing request body"})
|
|
|
|
+ return
|
|
|
|
+ case err != nil:
|
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|