From 630073233fd71193f0f8fc39f881b997552bbcbe Mon Sep 17 00:00:00 2001 From: NamH Date: Mon, 9 Dec 2024 23:08:36 +0700 Subject: [PATCH] chore: add backward compatible for thread (#1782) --- engine/common/thread.h | 15 +++++++++++++++ engine/controllers/threads.cc | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/engine/common/thread.h b/engine/common/thread.h index 480c0ba78..2bd5d866b 100644 --- a/engine/common/thread.h +++ b/engine/common/thread.h @@ -124,6 +124,21 @@ struct Thread : JsonSerializable { json["object"] = object; json["created_at"] = created_at; + // Deprecated: This is for backward compatibility. Please remove it later. (2-3 releases) to be sure + try { + auto it = metadata.find("title"); + if (it == metadata.end()) { + json["title"] = ""; + } else { + json["title"] = std::get(metadata["title"]); + } + + } catch (const std::bad_variant_access& ex) { + // std::cerr << "Error: value is not a string" << std::endl; + CTL_WRN("Error: value of title is not a string: " << ex.what()); + } + // End deprecated + if (tool_resources) { auto tool_result = tool_resources->ToJson(); if (tool_result.has_error()) { diff --git a/engine/controllers/threads.cc b/engine/controllers/threads.cc index e130dad88..81e14ce5a 100644 --- a/engine/controllers/threads.cc +++ b/engine/controllers/threads.cc @@ -26,6 +26,7 @@ void Threads::ListThreads( for (auto& msg : res.value()) { if (auto it = msg.ToJson(); it.has_value()) { it->removeMember("assistants"); + it->removeMember("title"); msg_arr.append(it.value()); } else { CTL_WRN("Failed to convert message to json: " + it.error()); @@ -86,8 +87,10 @@ void Threads::CreateThread( resp->setStatusCode(k400BadRequest); callback(resp); } else { - auto resp = - cortex_utils::CreateCortexHttpJsonResponse(res->ToJson().value()); + auto json_res = res->ToJson(); + json_res->removeMember("title"); + json_res->removeMember("assistants"); + auto resp = cortex_utils::CreateCortexHttpJsonResponse(json_res.value()); resp->setStatusCode(k200OK); callback(resp); } @@ -116,6 +119,7 @@ void Threads::RetrieveThread( callback(resp); } else { thread_to_json->removeMember("assistants"); + thread_to_json->removeMember("title"); auto resp = cortex_utils::CreateCortexHttpJsonResponse(thread_to_json.value()); resp->setStatusCode(k200OK); @@ -189,6 +193,8 @@ void Threads::ModifyThread( resp->setStatusCode(k400BadRequest); callback(resp); } else { + res->ToJson()->removeMember("title"); + res->ToJson()->removeMember("assistants"); auto resp = cortex_utils::CreateCortexHttpJsonResponse(res->ToJson().value()); resp->setStatusCode(k200OK);