From 63f0b8025d290c6d69c84bb20a46ba08f1a4efc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20Arma=C4=9Fan?= <70442658+ozanarmagan@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:27:59 +0300 Subject: [PATCH] Fix conversation model id generation (#1790) * Fix conversation model id generation * Fix typo --- src/core_api.cpp | 10 +--------- src/http_server.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 10 deletions(-) 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& 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(); - } - } 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(); + } else { + request->metadata = sole::uuid4().str(); + } + } catch (const nlohmann::json::parse_error& e) { + request->metadata = sole::uuid4().str(); + } } if(req->proceed_req == nullptr) {