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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Create conversation model id in request metadata (#1708)
Ozan Armağanf49696a13d53
diff --git a/include/conversation_model_manager.h b/include/conversation_model_manager.hindex 8caf1f15..5782e884 100644--- a/include/conversation_model_manager.h+++ b/include/conversation_model_manager.h@@ -17,7 +17,7 @@ class ConversationModelManagerConversationModelManager& operator=(const ConversationModelManager&) = delete;static Option<nlohmann::json> get_model(const std::string& model_id);- static Option<nlohmann::json> add_model(nlohmann::json model);+ static Option<nlohmann::json> add_model(nlohmann::json model, const std::string& model_id = "");static Option<nlohmann::json> delete_model(const std::string& model_id);static Option<nlohmann::json> update_model(const std::string& model_id, nlohmann::json model);static Option<nlohmann::json> get_all_models();diff --git a/src/conversation_model_manager.cpp b/src/conversation_model_manager.cppindex 2a72056a..4cd81511 100644--- a/src/conversation_model_manager.cpp+++ b/src/conversation_model_manager.cpp@@ -11,14 +11,15 @@ Option<nlohmann::json> ConversationModelManager::get_model(const std::string& moreturn Option<nlohmann::json>(it->second);}-Option<nlohmann::json> ConversationModelManager::add_model(nlohmann::json model) {+Option<nlohmann::json> ConversationModelManager::add_model(nlohmann::json model, const std::string& model_id) {std::unique_lock lock(models_mutex);auto validate_res = ConversationModel::validate_model(model);if (!validate_res.ok()) {return Option<nlohmann::json>(validate_res.code(), validate_res.error());}- auto model_id = sole::uuid4().str();- model["id"] = model_id;+++ model["id"] = model_id.empty() ? sole::uuid4().str() : model_id;auto model_key = get_model_key(model_id);bool insert_op = store->insert(model_key, model.dump(0));diff --git a/src/core_api.cpp b/src/core_api.cppindex 67bb55dd..3a9dac74 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -2879,7 +2879,9 @@ bool post_conversation_model(const std::shared_ptr<http_req>& req, const std::shreturn false;}- auto add_model_op = ConversationModelManager::add_model(req_json);+ const std::string& model_id = req->metadata;++ auto add_model_op = ConversationModelManager::add_model(req_json, model_id);if(!add_model_op.ok()) {res->set(add_model_op.code(), add_model_op.error());diff --git a/src/http_server.cpp b/src/http_server.cppindex 6981b7df..547e3e4b 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -11,6 +11,7 @@#include "raft_server.h"#include "logger.h"#include "ratelimit_manager.h"+#include "sole.hpp"HttpServer::HttpServer(const std::string & version, const std::string & listen_address,uint32_t listen_port, const std::string & ssl_cert_path, const std::string & ssl_cert_key_path,@@ -545,6 +546,10 @@ int HttpServer::catch_all_handler(h2o_handler_t *_h2o_handler, h2o_req_t *req) {request->metadata = StringUtils::randstring(AuthManager::GENERATED_KEY_LEN);}+ if(rpath->action == "conversations/models:create") {+ request->metadata = sole::uuid4().str();+ }+if(req->proceed_req == nullptr) {// Full request body is already available, so we don't care if handler is async or not//LOG(INFO) << "Full request body is already available: " << req->entity.len;