From f7ee0123008dbdb3fd5954438d12196951b58b78 Mon Sep 17 00:00:00 2001 From: jmorganca Date: Sat, 13 Jul 2024 15:08:00 -0700 Subject: [PATCH] server: prepend system message in chat handler --- server/routes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/routes.go b/server/routes.go index 5b6d0978..edaec691 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1181,6 +1181,10 @@ func (s *Server) ChatHandler(c *gin.Context) { return } + if req.Messages[0].Role != "system" { + req.Messages = append([]api.Message{{Role: "system", Content: m.System}}, req.Messages...) + } + prompt, images, err := chatPrompt(c.Request.Context(), m, r.Tokenize, opts, req.Messages) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})