Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0bd7178

Browse files
committed
fix ci
1 parent 263382d commit 0bd7178

File tree

7 files changed

+59
-17
lines changed

7 files changed

+59
-17
lines changed

engine/common/thread.h

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <json/reader.h>
44
#include <json/value.h>
55
#include <json/writer.h>
6-
#include <optional>
76
#include "common/thread_tool_resources.h"
87
#include "common/variant_map.h"
98
#include "json_serializable.h"
@@ -36,7 +35,7 @@ struct Thread : JsonSerializable {
3635
* of tool. For example, the code_interpreter tool requires a list of
3736
* file IDs, while the file_search tool requires a list of vector store IDs.
3837
*/
39-
std::optional<std::unique_ptr<ThreadToolResources>> tool_resources;
38+
std::unique_ptr<ThreadToolResources> tool_resources;
4039

4140
/**
4241
* Set of 16 key-value pairs that can be attached to an object.
@@ -57,7 +56,30 @@ struct Thread : JsonSerializable {
5756
if (thread.created_at == 0 && json["created"].asUInt64() != 0) {
5857
thread.created_at = json["created"].asUInt64() / 1000;
5958
}
60-
// TODO: namh parse tool_resources
59+
60+
if (json.isMember("tool_resources") && !json["tool_resources"].isNull()) {
61+
const auto& tool_json = json["tool_resources"];
62+
63+
if (tool_json.isMember("code_interpreter")) {
64+
auto code_interpreter = std::make_unique<ThreadCodeInterpreter>();
65+
const auto& file_ids = tool_json["code_interpreter"]["file_ids"];
66+
if (file_ids.isArray()) {
67+
for (const auto& file_id : file_ids) {
68+
code_interpreter->file_ids.push_back(file_id.asString());
69+
}
70+
}
71+
thread.tool_resources = std::move(code_interpreter);
72+
} else if (tool_json.isMember("file_search")) {
73+
auto file_search = std::make_unique<ThreadFileSearch>();
74+
const auto& store_ids = tool_json["file_search"]["vector_store_ids"];
75+
if (store_ids.isArray()) {
76+
for (const auto& store_id : store_ids) {
77+
file_search->vector_store_ids.push_back(store_id.asString());
78+
}
79+
}
80+
thread.tool_resources = std::move(file_search);
81+
}
82+
}
6183

6284
if (json["metadata"].isObject() && !json["metadata"].empty()) {
6385
auto res = Cortex::ConvertJsonValueToMap(json["metadata"]);
@@ -78,7 +100,24 @@ struct Thread : JsonSerializable {
78100
json["id"] = id;
79101
json["object"] = object;
80102
json["created_at"] = created_at;
81-
// TODO: namh handle tool_resources
103+
104+
if (tool_resources) {
105+
auto tool_result = tool_resources->ToJson();
106+
if (tool_result.has_error()) {
107+
return cpp::fail("Failed to serialize tool_resources: " +
108+
tool_result.error());
109+
}
110+
111+
Json::Value tool_json;
112+
if (auto code_interpreter =
113+
dynamic_cast<ThreadCodeInterpreter*>(tool_resources.get())) {
114+
tool_json["code_interpreter"] = tool_result.value();
115+
} else if (auto file_search =
116+
dynamic_cast<ThreadFileSearch*>(tool_resources.get())) {
117+
tool_json["file_search"] = tool_result.value();
118+
}
119+
json["tool_resources"] = tool_json;
120+
}
82121

83122
Json::Value metadata_json{Json::objectValue};
84123
for (const auto& [key, value] : metadata) {

engine/controllers/threads.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Threads::CreateThread(
6565
}
6666
}
6767

68-
auto res = thread_service_->CreateThread(std::nullopt, metadata);
68+
auto res = thread_service_->CreateThread(nullptr, metadata);
6969

7070
if (res.has_error()) {
7171
Json::Value ret;
@@ -170,7 +170,7 @@ void Threads::ModifyThread(
170170

171171
// TODO: namh handle tools
172172
auto res =
173-
thread_service_->ModifyThread(thread_id, std::nullopt, metadata.value());
173+
thread_service_->ModifyThread(thread_id, nullptr, metadata.value());
174174
if (res.has_error()) {
175175
Json::Value ret;
176176
ret["message"] = res.error();

engine/repositories/message_fs_repository.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "message_fs_repository.h"
22
#include <fstream>
3+
#include <mutex>
34
#include "utils/result.hpp"
45

56
std::filesystem::path MessageFsRepository::GetMessagePath(

engine/repositories/thread_fs_repository.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "thread_fs_repository.h"
22
#include <fstream>
3+
#include <mutex>
34

45
cpp::result<std::vector<OpenAi::Thread>, std::string>
56
ThreadFsRepository::ListThreads(uint8_t limit, const std::string& order,

engine/repositories/thread_fs_repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ThreadFsRepository : public ThreadRepository {
3434
cpp::result<void, std::string> SaveThread(OpenAi::Thread& thread);
3535

3636
public:
37-
explicit ThreadFsRepository(std::filesystem::path data_folder_path)
37+
explicit ThreadFsRepository(const std::filesystem::path& data_folder_path)
3838
: data_folder_path_{data_folder_path} {
3939
CTL_INF("Constructing ThreadFsRepository..");
4040
auto thread_container_path = data_folder_path_ / kThreadContainerFolderName;

engine/services/thread_service.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "utils/ulid/ulid.hh"
44

55
cpp::result<OpenAi::Thread, std::string> ThreadService::CreateThread(
6-
std::optional<std::unique_ptr<OpenAi::ThreadToolResources>> tool_resources,
6+
std::unique_ptr<OpenAi::ThreadToolResources> tool_resources,
77
std::optional<Cortex::VariantMap> metadata) {
88
LOG_TRACE << "CreateThread";
99

@@ -20,8 +20,8 @@ cpp::result<OpenAi::Thread, std::string> ThreadService::CreateThread(
2020
thread.object = "thread";
2121
thread.created_at = seconds_since_epoch;
2222

23-
if (tool_resources.has_value()) {
24-
thread.tool_resources = std::move(tool_resources.value());
23+
if (tool_resources) {
24+
thread.tool_resources = std::move(tool_resources);
2525
}
2626
thread.metadata = metadata.value_or(Cortex::VariantMap{});
2727

@@ -42,21 +42,23 @@ ThreadService::ListThreads(uint8_t limit, const std::string& order,
4242

4343
cpp::result<OpenAi::Thread, std::string> ThreadService::RetrieveThread(
4444
const std::string& thread_id) const {
45-
LOG_TRACE << "RetriveThread: " << thread_id;
45+
CTL_INF("RetrieveThread: " + thread_id);
4646
return thread_repository_->RetrieveThread(thread_id);
4747
}
4848

4949
cpp::result<OpenAi::Thread, std::string> ThreadService::ModifyThread(
5050
const std::string& thread_id,
51-
std::optional<std::unique_ptr<OpenAi::ThreadToolResources>> tool_resources,
51+
std::unique_ptr<OpenAi::ThreadToolResources> tool_resources,
5252
std::optional<Cortex::VariantMap> metadata) {
5353
LOG_TRACE << "ModifyThread " << thread_id;
5454
auto retrieve_res = RetrieveThread(thread_id);
5555
if (retrieve_res.has_error()) {
5656
return cpp::fail("Failed to retrieve thread: " + retrieve_res.error());
5757
}
5858

59-
retrieve_res->tool_resources = std::move(tool_resources.value());
59+
if (tool_resources) {
60+
retrieve_res->tool_resources = std::move(tool_resources);
61+
}
6062
retrieve_res->metadata = std::move(metadata.value());
6163

6264
auto res = thread_repository_->ModifyThread(retrieve_res.value());

engine/services/thread_service.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <optional>
34
#include "common/repository/thread_repository.h"
45
#include "common/thread_tool_resources.h"
56
#include "common/variant_map.h"
@@ -11,8 +12,7 @@ class ThreadService {
1112
: thread_repository_{thread_repository} {}
1213

1314
cpp::result<OpenAi::Thread, std::string> CreateThread(
14-
std::optional<std::unique_ptr<OpenAi::ThreadToolResources>>
15-
tool_resources,
15+
std::unique_ptr<OpenAi::ThreadToolResources> tool_resources,
1616
std::optional<Cortex::VariantMap> metadata);
1717

1818
cpp::result<std::vector<OpenAi::Thread>, std::string> ListThreads(
@@ -24,8 +24,7 @@ class ThreadService {
2424

2525
cpp::result<OpenAi::Thread, std::string> ModifyThread(
2626
const std::string& thread_id,
27-
std::optional<std::unique_ptr<OpenAi::ThreadToolResources>>
28-
tool_resources,
27+
std::unique_ptr<OpenAi::ThreadToolResources> tool_resources,
2928
std::optional<Cortex::VariantMap> metadata);
3029

3130
cpp::result<std::string, std::string> DeleteThread(

0 commit comments

Comments
 (0)