diff --git a/src/text_embedder_remote.cpp b/src/text_embedder_remote.cpp index f13f86ed..4e844871 100644 --- a/src/text_embedder_remote.cpp +++ b/src/text_embedder_remote.cpp @@ -148,6 +148,8 @@ embedding_res_t OpenAIEmbedder::Embed(const std::string& text) { try { json_res = nlohmann::json::parse(res); } catch (const std::exception& e) { + json_res = nlohmann::json::object(); + json_res["error"] = "Malformed response from OpenAI API."; } nlohmann::json embedding_res = nlohmann::json::object(); @@ -200,6 +202,7 @@ std::vector OpenAIEmbedder::batch_embed(const std::vector GoogleEmbedder::is_model_valid(const nlohmann::json& model_config, try { json_res = nlohmann::json::parse(res); } catch (const std::exception& e) { + json_res = nlohmann::json::object(); + json_res["error"] = "Malformed response from Google API."; } if(res_code == 408) { return Option(408, "Google API timeout."); @@ -321,7 +326,7 @@ embedding_res_t GoogleEmbedder::Embed(const std::string& text) { nlohmann::json json_res = nlohmann::json::parse(res); } catch (const std::exception& e) { json_res = nlohmann::json::object(); - json_res["error"] = res; + json_res["error"] = "Malformed response from Google API." } nlohmann::json embedding_res = nlohmann::json::object(); embedding_res["response"] = json_res; @@ -473,7 +478,7 @@ embedding_res_t GCPEmbedder::Embed(const std::string& text) { json_res = nlohmann::json::parse(res); } catch (const std::exception& e) { json_res = nlohmann::json::object(); - json_res["error"] = "Got malformed response from GCP API."; + json_res["error"] = "Malformed response from GCP API."; } nlohmann::json embedding_res = nlohmann::json::object(); embedding_res["response"] = json_res; @@ -556,7 +561,7 @@ std::vector GCPEmbedder::batch_embed(const std::vector