prompt: Don't trim whitespace from prompts

New lines can be an important part of a user's prompt and trimming
it can alter the results. We previously only trimmed prompts with
images but refactoring brought this behavior to all prompts, where
it became more noticable.

The /generate endpoint adds less whitespace and therefore doesn't
need to trim it out - this brings the same behavior to /chat.

Thanks to @gabe-l-hart for spotting the issue!

Fixes #7795
This commit is contained in:
Jesse Gross 2024-12-06 15:12:30 -08:00 committed by Jesse Gross
parent da09488fbf
commit 900f64e6be
2 changed files with 6 additions and 7 deletions

View File

@ -114,7 +114,6 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
ID: len(images),
Data: i,
}
imgPrompt = " "
}
imgTag := fmt.Sprintf("[img-%d]", imgData.ID)
@ -126,7 +125,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
images = append(images, imgData)
}
msgs[currMsgIdx+cnt].Content = strings.TrimSpace(prefix + imgPrompt + prompt)
msgs[currMsgIdx+cnt].Content = prefix + imgPrompt + prompt
}
// truncate any messages that do not fit into the context window