From c25ffde91d3d2f8913224ac9bbc28736a4981fa3 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Wed, 13 Nov 2024 16:49:01 -0800 Subject: [PATCH] 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 --- llama/runner/runner.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/llama/runner/runner.go b/llama/runner/runner.go index c034bc46..0ae50608 100644 --- a/llama/runner/runner.go +++ b/llama/runner/runner.go @@ -163,15 +163,13 @@ func (s *Server) inputs(prompt string, images []ImageData) ([]input, error) { for i, part := range parts { // text - tokenize - if strings.TrimSpace(part) != "" { - tokens, err := s.lc.Model().Tokenize(part, i == 0, true) - if err != nil { - return nil, err - } + tokens, err := s.lc.Model().Tokenize(part, i == 0, true) + if err != nil { + return nil, err + } - for _, t := range tokens { - inputs = append(inputs, input{token: t}) - } + for _, t := range tokens { + inputs = append(inputs, input{token: t}) } // image - generate image embedding