validate api options fields from map (#711)

This commit is contained in:
Bruce MacDonald
2023-10-12 11:18:11 -04:00
committed by GitHub
parent 56497663c8
commit 7804b8fab9
2 changed files with 13 additions and 1 deletions

View File

@@ -68,7 +68,6 @@ func load(ctx context.Context, workDir string, model *Model, reqOpts map[string]
}
if err := opts.FromMap(reqOpts); err != nil {
log.Printf("could not merge model options: %v", err)
return err
}
@@ -186,6 +185,10 @@ func GenerateHandler(c *gin.Context) {
// TODO: set this duration from the request if specified
sessionDuration := defaultSessionDuration
if err := load(c.Request.Context(), workDir, model, req.Options, sessionDuration); err != nil {
if errors.Is(err, api.ErrInvalidOpts) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}