fix base64 test

This commit is contained in:
Reza Kakhki 2024-12-24 15:56:18 +01:00
parent 0a753fbd1c
commit c66b1a7611
2 changed files with 4 additions and 1 deletions

View file

@ -202,7 +202,7 @@ def test_embedding_openai_library_base64():
server.start() server.start()
test_input = "Test base64 embedding output" test_input = "Test base64 embedding output"
res = server.make_request("POST", "/embeddings", data={ res = server.make_request("POST", "/v1/embeddings", data={
"input": test_input, "input": test_input,
"encoding_format": "base64" "encoding_format": "base64"
}) })

View file

@ -3,6 +3,7 @@
#include "common.h" #include "common.h"
#include "log.h" #include "log.h"
#include "llama.h" #include "llama.h"
#include "common/base64.hpp"
#ifndef NDEBUG #ifndef NDEBUG
// crash the server in debug mode, otherwise send an http 500 error // crash the server in debug mode, otherwise send an http 500 error
@ -596,6 +597,8 @@ static json format_embeddings_response_oaicompat(const json & request, const jso
int32_t n_tokens = 0; int32_t n_tokens = 0;
int i = 0; int i = 0;
for (const auto & elem : embeddings) { for (const auto & elem : embeddings) {
json embedding_obj;
if (use_base64) { if (use_base64) {
const auto& vec = json_value(elem, "embedding", json::array()).get<std::vector<float>>(); const auto& vec = json_value(elem, "embedding", json::array()).get<std::vector<float>>();
const char* data_ptr = reinterpret_cast<const char*>(vec.data()); const char* data_ptr = reinterpret_cast<const char*>(vec.data());