Skip to content

Commit

Permalink
chore: add backward compatible for thread (#1782)
Browse files Browse the repository at this point in the history
  • Loading branch information
namchuai authored Dec 9, 2024
1 parent 0b5b9aa commit 6300732
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions engine/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(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()) {
Expand Down
10 changes: 8 additions & 2 deletions engine/controllers/threads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6300732

Please sign in to comment.