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.
This commit is contained in:
mudler 2023-05-05 18:05:29 +02:00
parent b49721cdd1
commit e62ee2bc06

View File

@ -78,7 +78,19 @@ func ModelEmbedding(s string, loader *model.ModelLoader, c Config) (func() ([]fl
l.Lock()
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
}