runner.go: Don't trim whitespace from inputs

It's possible to get prompts that consist entirely of whitespace -
this is most likely to happen when generating embeddings. Currently,
we will trim this away, leaving an empty prompt, which will then
generate an error.

Generating embeddings from whitespace should not trigger an error,
as this may break pipelines. It's better to just leave the whitespace
in place and process what we are given. This is consistent with
past versions of Ollama.

Bug #7578
This commit is contained in:
Jesse Gross 2024-11-13 16:49:01 -08:00 committed by Jesse Gross
parent 17b386a891
commit c25ffde91d

View file

@ -163,7 +163,6 @@ func (s *Server) inputs(prompt string, images []ImageData) ([]input, error) {
for i, part := range parts { for i, part := range parts {
// text - tokenize // text - tokenize
if strings.TrimSpace(part) != "" {
tokens, err := s.lc.Model().Tokenize(part, i == 0, true) tokens, err := s.lc.Model().Tokenize(part, i == 0, true)
if err != nil { if err != nil {
return nil, err return nil, err
@ -172,7 +171,6 @@ func (s *Server) inputs(prompt string, images []ImageData) ([]input, error) {
for _, t := range tokens { for _, t := range tokens {
inputs = append(inputs, input{token: t}) inputs = append(inputs, input{token: t})
} }
}
// image - generate image embedding // image - generate image embedding
if i < len(matches) { if i < len(matches) {