forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_attachment.h
More file actions
55 lines (43 loc) · 1.33 KB
/
message_attachment.h
File metadata and controls
55 lines (43 loc) · 1.33 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
#pragma once
#include <json/reader.h>
#include "common/json_serializable.h"
namespace OpenAi {
// The tools to add this file to.
struct Tool {
std::string type;
Tool(const std::string& type) : type{type} {}
virtual ~Tool() = default;
};
// The type of tool being defined: code_interpreter
struct MessageCodeInterpreter : Tool {
MessageCodeInterpreter() : Tool{"code_interpreter"} {}
~MessageCodeInterpreter() = default;
};
// The type of tool being defined: file_search
struct MessageFileSearch : Tool {
MessageFileSearch() : Tool{"file_search"} {}
~MessageFileSearch() = default;
};
// A list of files attached to the message, and the tools they were added to.
struct Attachment : JsonSerializable {
// The ID of the file to attach to the message.
std::string file_id;
std::vector<Tool> tools;
cpp::result<Json::Value, std::string> ToJson() override {
try {
Json::Value json;
json["file_id"] = file_id;
Json::Value tools_json_arr{Json::arrayValue};
for (auto& tool : tools) {
Json::Value tool_json;
tool_json["type"] = tool.type;
tools_json_arr.append(tool_json);
}
json["tools"] = tools_json_arr;
return json;
} catch (const std::exception& e) {
return cpp::fail(std::string("ToJson failed: ") + e.what());
}
}
};
}; // namespace OpenAi