Change the order of context and prompt.

This commit is contained in:
Vyacheslav Moskalev 2024-08-01 19:25:56 +07:00
parent 6bc5c13758
commit 49a5483139

View file

@ -188,21 +188,22 @@ func (s *Server) GenerateHandler(c *gin.Context) {
} }
var b bytes.Buffer var b bytes.Buffer
if err := tmpl.Execute(&b, values); err != nil { var t bytes.Buffer
if err := tmpl.Execute(&t, values); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
if req.Context != nil { if req.Context != nil {
s, err := r.Detokenize(c.Request.Context(), req.Context) prev, 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(prev)
b.WriteString(s)
} }
b.WriteString(t.String());
prompt = b.String() prompt = b.String()
} }
@ -242,12 +243,12 @@ func (s *Server) GenerateHandler(c *gin.Context) {
res.LoadDuration = checkpointLoaded.Sub(checkpointStart) res.LoadDuration = checkpointLoaded.Sub(checkpointStart)
if !req.Raw { if !req.Raw {
tokens, err := r.Tokenize(c.Request.Context(), prompt+sb.String()) tokens, err := r.Tokenize(c.Request.Context(), prompt + sb.String())
if err != nil { if err != nil {
ch <- gin.H{"error": err.Error()} ch <- gin.H{"error": err.Error()}
return return
} }
res.Context = tokens res.Context = tokens[:]
} }
} }