Do not repeat system prompt for chat templating (#2241)

This commit is contained in:
Jeffrey Morgan 2024-01-28 14:15:56 -08:00 committed by GitHub
parent 311f8e0c3f
commit e4b9b72f2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -119,10 +119,6 @@ func Prompt(promptTemplate string, p PromptVars) (string, error) {
// PreResponsePrompt returns the prompt before the response tag // PreResponsePrompt returns the prompt before the response tag
func (m *Model) PreResponsePrompt(p PromptVars) (string, error) { func (m *Model) PreResponsePrompt(p PromptVars) (string, error) {
if p.System == "" {
// use the default system prompt for this model if one is not specified
p.System = m.System
}
pre, _, err := extractParts(m.Template) pre, _, err := extractParts(m.Template)
if err != nil { if err != nil {
return "", err return "", err

View file

@ -239,6 +239,11 @@ func GenerateHandler(c *gin.Context) {
Prompt: req.Prompt, Prompt: req.Prompt,
First: len(req.Context) == 0, First: len(req.Context) == 0,
} }
if promptVars.System == "" {
promptVars.System = model.System
}
p, err := model.PreResponsePrompt(promptVars) p, err := model.PreResponsePrompt(promptVars)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})