mirror of
https://github.com/ollama/ollama.git
synced 2025-11-10 21:17:32 +01:00
simplfied logic and added tests
This commit is contained in:
@@ -256,8 +256,7 @@ func (w *EmbedWriter) writeResponse(data []byte) (int, error) {
|
||||
}
|
||||
|
||||
w.ResponseWriter.Header().Set("Content-Type", "application/json")
|
||||
converted := openai.ToEmbeddingList(w.model, embedResponse, w.encodingFormat)
|
||||
err = json.NewEncoder(w.ResponseWriter).Encode(converted)
|
||||
err = json.NewEncoder(w.ResponseWriter).Encode(openai.ToEmbeddingList(w.model, embedResponse, w.encodingFormat))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -383,15 +383,11 @@ func ToListCompletion(r api.ListResponse) ListCompletion {
|
||||
// encodingFormat can be "float", "base64", or empty (defaults to "float")
|
||||
func ToEmbeddingList(model string, r api.EmbedResponse, encodingFormat string) EmbeddingList {
|
||||
if r.Embeddings != nil {
|
||||
if encodingFormat == "" {
|
||||
encodingFormat = "float"
|
||||
}
|
||||
|
||||
var data []Embedding
|
||||
for i, e := range r.Embeddings {
|
||||
var embedding any
|
||||
if encodingFormat == "base64" {
|
||||
embedding = convertFloatsToBase64(e)
|
||||
if strings.EqualFold(encodingFormat, "base64") {
|
||||
embedding = floatsToBase64(e)
|
||||
} else {
|
||||
embedding = e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user