Merge pull request #6115 from slouffka/fix-context

Fix context in /api/generate grows too much (#5980).
This commit is contained in:
Michael Yang 2024-08-01 15:13:59 -07:00 committed by GitHub
commit ff7c9060ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -188,21 +188,20 @@ func (s *Server) GenerateHandler(c *gin.Context) {
} }
var b bytes.Buffer var b bytes.Buffer
if err := tmpl.Execute(&b, values); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if req.Context != nil { if req.Context != nil {
s, err := r.Detokenize(c.Request.Context(), req.Context) s, err := r.Detokenize(c.Request.Context(), req.Context)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
b.WriteString(s) b.WriteString(s)
} }
if err := tmpl.Execute(&b, values); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
prompt = b.String() prompt = b.String()
} }
@ -247,7 +246,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
ch <- gin.H{"error": err.Error()} ch <- gin.H{"error": err.Error()}
return return
} }
res.Context = append(req.Context, tokens...) res.Context = tokens
} }
} }