mirror of
https://github.com/ollama/ollama.git
synced 2025-11-10 23:37:17 +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")
|
w.ResponseWriter.Header().Set("Content-Type", "application/json")
|
||||||
converted := openai.ToEmbeddingList(w.model, embedResponse, w.encodingFormat)
|
err = json.NewEncoder(w.ResponseWriter).Encode(openai.ToEmbeddingList(w.model, embedResponse, w.encodingFormat))
|
||||||
err = json.NewEncoder(w.ResponseWriter).Encode(converted)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,15 +383,11 @@ func ToListCompletion(r api.ListResponse) ListCompletion {
|
|||||||
// encodingFormat can be "float", "base64", or empty (defaults to "float")
|
// encodingFormat can be "float", "base64", or empty (defaults to "float")
|
||||||
func ToEmbeddingList(model string, r api.EmbedResponse, encodingFormat string) EmbeddingList {
|
func ToEmbeddingList(model string, r api.EmbedResponse, encodingFormat string) EmbeddingList {
|
||||||
if r.Embeddings != nil {
|
if r.Embeddings != nil {
|
||||||
if encodingFormat == "" {
|
|
||||||
encodingFormat = "float"
|
|
||||||
}
|
|
||||||
|
|
||||||
var data []Embedding
|
var data []Embedding
|
||||||
for i, e := range r.Embeddings {
|
for i, e := range r.Embeddings {
|
||||||
var embedding any
|
var embedding any
|
||||||
if encodingFormat == "base64" {
|
if strings.EqualFold(encodingFormat, "base64") {
|
||||||
embedding = convertFloatsToBase64(e)
|
embedding = floatsToBase64(e)
|
||||||
} else {
|
} else {
|
||||||
embedding = e
|
embedding = e
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user