forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_resources.h
More file actions
114 lines (86 loc) · 2.99 KB
/
tool_resources.h
File metadata and controls
114 lines (86 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
#include <string>
#include <vector>
#include "common/json_serializable.h"
namespace OpenAi {
struct ToolResources : JsonSerializable {
ToolResources() = default;
ToolResources(const ToolResources&) = delete;
ToolResources& operator=(const ToolResources&) = delete;
ToolResources(ToolResources&&) noexcept = default;
ToolResources& operator=(ToolResources&&) noexcept = default;
virtual ~ToolResources() = default;
virtual cpp::result<Json::Value, std::string> ToJson() override = 0;
};
struct CodeInterpreter : ToolResources {
CodeInterpreter() = default;
~CodeInterpreter() override = default;
CodeInterpreter(const CodeInterpreter&) = delete;
CodeInterpreter& operator=(const CodeInterpreter&) = delete;
CodeInterpreter(CodeInterpreter&& other) noexcept
: ToolResources(std::move(other)), file_ids(std::move(other.file_ids)) {}
CodeInterpreter& operator=(CodeInterpreter&& other) noexcept {
if (this != &other) {
ToolResources::operator=(std::move(other));
file_ids = std::move(other.file_ids);
}
return *this;
}
std::vector<std::string> file_ids;
static cpp::result<CodeInterpreter, std::string> FromJson(
const Json::Value& json) {
CodeInterpreter code_interpreter;
if (json.isMember("file_ids")) {
for (const auto& file_id : json["file_ids"]) {
code_interpreter.file_ids.push_back(file_id.asString());
}
}
return code_interpreter;
}
cpp::result<Json::Value, std::string> ToJson() override {
Json::Value json;
Json::Value file_ids_json{Json::arrayValue};
for (auto& file_id : file_ids) {
file_ids_json.append(file_id);
}
json["file_ids"] = file_ids_json;
return json;
}
};
struct FileSearch : ToolResources {
FileSearch() = default;
~FileSearch() override = default;
FileSearch(const FileSearch&) = delete;
FileSearch& operator=(const FileSearch&) = delete;
FileSearch(FileSearch&& other) noexcept
: ToolResources(std::move(other)),
vector_store_ids{std::move(other.vector_store_ids)} {}
FileSearch& operator=(FileSearch&& other) noexcept {
if (this != &other) {
ToolResources::operator=(std::move(other));
vector_store_ids = std::move(other.vector_store_ids);
}
return *this;
}
std::vector<std::string> vector_store_ids;
static cpp::result<FileSearch, std::string> FromJson(
const Json::Value& json) {
FileSearch file_search;
if (json.isMember("vector_store_ids")) {
for (const auto& vector_store_id : json["vector_store_ids"]) {
file_search.vector_store_ids.push_back(vector_store_id.asString());
}
}
return file_search;
}
cpp::result<Json::Value, std::string> ToJson() override {
Json::Value json;
Json::Value vector_store_ids_json{Json::arrayValue};
for (auto& vector_store_id : vector_store_ids) {
vector_store_ids_json.append(vector_store_id);
}
json["vector_store_ids"] = vector_store_ids_json;
return json;
}
};
} // namespace OpenAi