Skip to content

Commit

Permalink
runner.go: Don't trim whitespace from inputs
Browse files Browse the repository at this point in the history
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 ollama#7578
  • Loading branch information
jessegross committed Nov 14, 2024
1 parent 17b386a commit c25ffde
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions llama/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c25ffde

Please sign in to comment.