return error in generate response

This commit is contained in:
Michael Yang
2023-07-07 14:04:43 -07:00
parent 2d49197b3b
commit edba935d67
4 changed files with 38 additions and 7 deletions

View File

@@ -4,7 +4,6 @@ import (
"embed"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"math"
@@ -46,7 +45,7 @@ func generate(c *gin.Context) {
req.PredictOptions = &api.DefaultPredictOptions
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
@@ -66,7 +65,7 @@ func generate(c *gin.Context) {
model, err := llama.New(req.Model, modelOpts)
if err != nil {
fmt.Println("Loading the model failed:", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
defer model.Free()
@@ -80,7 +79,7 @@ func generate(c *gin.Context) {
if template := templates.Lookup(match); template != nil {
var sb strings.Builder
if err := template.Execute(&sb, req); err != nil {
fmt.Println("Prompt template failed:", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}