Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix conversation model id generation (#1790)

Ozan Armağan63f0b8025d29
diff --git a/src/core_api.cpp b/src/core_api.cpp
index d0bcae52..76971232 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -2989,15 +2989,7 @@ bool post_conversation_model(const std::shared_ptr<http_req>& req, const std::sh
return false;
}
- std::string model_id = "";
- try {
- nlohmann::json parsed_json = nlohmann::json::parse(req->body);
- if(parsed_json.count("id") != 0 && parsed_json["id"].is_string()) {
- model_id = parsed_json["id"].get<std::string>();
- }
- } catch(const std::exception& e) {
-
- }
+ std::string model_id = req->metadata;
auto add_model_op = ConversationModelManager::add_model(req_json, model_id);
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 262f5c9c..32a344c9 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -547,7 +547,16 @@ int HttpServer::catch_all_handler(h2o_handler_t *_h2o_handler, h2o_req_t *req) {
}
if(rpath->action == "conversations/models:create") {
- request->metadata = sole::uuid4().str();
+ try {
+ nlohmann::json body_json = nlohmann::json::parse(request->body);
+ if(body_json.count("id") != 0 && body_json["id"].is_string()) {
+ request->metadata = body_json["id"].get<std::string>();
+ } else {
+ request->metadata = sole::uuid4().str();
+ }
+ } catch (const nlohmann::json::parse_error& e) {
+ request->metadata = sole::uuid4().str();
+ }
}
if(req->proceed_req == nullptr) {