fix: remove trailing 0s from embeddings

This happens when no max_tokens are set, so by default go-llama
allocates more space for the slice and padding happens.
agent
mudler 2 years ago
parent b49721cdd1
commit e62ee2bc06
  1. 14
      api/prediction.go

@ -78,7 +78,19 @@ func ModelEmbedding(s string, loader *model.ModelLoader, c Config) (func() ([]fl
l.Lock() l.Lock()
defer l.Unlock() defer l.Unlock()
return fn() embeds, err := fn()
if err != nil {
return embeds, err
}
// Remove trailing 0s
for i := len(embeds) - 1; i >= 0; i-- {
if embeds[i] == 0.0 {
embeds = embeds[:i]
} else {
break
}
}
return embeds, nil
}, nil }, nil
} }

Loading…
Cancel
Save