-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathmessage_content_refusal.h
46 lines (35 loc) · 1.11 KB
/
message_content_refusal.h
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
#pragma once
#include "common/message_content.h"
namespace OpenAi {
// The refusal content generated by the assistant.
struct Refusal : Content {
// Always refusal.
Refusal(const std::string& refusal) : Content("refusal"), refusal{refusal} {}
Refusal(Refusal&&) noexcept = default;
Refusal& operator=(Refusal&&) noexcept = default;
Refusal(const Refusal&) = delete;
Refusal& operator=(const Refusal&) = delete;
std::string refusal;
static cpp::result<Refusal, std::string> FromJson(Json::Value&& json) {
if (json.empty()) {
return cpp::fail("Json string is empty");
}
try {
Refusal content{std::move(json["refusal"].asString())};
return content;
} catch (const std::exception& e) {
return cpp::fail(std::string("FromJson failed: ") + e.what());
}
}
cpp::result<Json::Value, std::string> ToJson() override {
try {
Json::Value json;
json["type"] = type;
json["refusal"] = refusal;
return json;
} catch (const std::exception& e) {
return cpp::fail(std::string("ToJson failed: ") + e.what());
}
}
};
} // namespace OpenAi