Skip to content

Commit

Permalink
fix ci windows
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
namchuai committed Dec 2, 2024
1 parent 3ee1e2b commit 2578833
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 21 deletions.
19 changes: 14 additions & 5 deletions engine/common/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace ThreadMessage {

// Represents a message within a thread.
struct Message : JsonSerializable {
Message() = default;

Message(Message&&) = default;

Message& operator=(Message&&) = default;

Message(const Message&) = delete;

Message& operator=(const Message&) = delete;

// The identifier, which can be referenced in API endpoints.
std::string id;
Expand Down Expand Up @@ -82,19 +91,19 @@ struct Message : JsonSerializable {
if (message.created_at == 0 && root["created"].asUInt64() != 0) {
message.created_at = root["created"].asUInt64() / 1000;
}
message.thread_id = root["thread_id"].asString();
message.status = StatusFromString(root["status"].asString());
message.thread_id = std::move(root["thread_id"].asString());
message.status = StatusFromString(std::move(root["status"].asString()));

message.incomplete_details =
IncompleteDetail::FromJson(std::move(root["incomplete_details"]))
.value();
message.completed_at = root["completed_at"].asUInt();
message.incomplete_at = root["incomplete_at"].asUInt();
message.role = RoleFromString(root["role"].asString());
message.role = RoleFromString(std::move(root["role"].asString()));
message.content = ParseContents(std::move(root["content"])).value();

message.assistant_id = root["assistant_id"].asString();
message.run_id = root["run_id"].asString();
message.assistant_id = std::move(root["assistant_id"].asString());
message.run_id = std::move(root["run_id"].asString());
message.attachments =
ParseAttachments(std::move(root["attachments"])).value();

Expand Down
8 changes: 8 additions & 0 deletions engine/common/message_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ struct Content : JsonSerializable {

Content(const std::string& type) : type{type} {}

Content(const Content&) = delete;

Content& operator=(const Content&) = delete;

Content(Content&&) noexcept = default;

Content& operator=(Content&&) noexcept = default;

virtual ~Content() = default;
};
}; // namespace ThreadMessage
24 changes: 21 additions & 3 deletions engine/common/message_content_image_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ struct ImageFile {

// Specifies the detail level of the image if specified by the user. low uses fewer tokens, you can opt in to high resolution using high.
std::string detail;

ImageFile() = default;

ImageFile(ImageFile&&) noexcept = default;

ImageFile& operator=(ImageFile&&) noexcept = default;

ImageFile(const ImageFile&) = delete;

ImageFile& operator=(const ImageFile&) = delete;
};

// References an image File in the content of a message.
struct ImageFileContent : Content {

ImageFileContent() : Content("image_file") {}

ImageFileContent(ImageFileContent&&) noexcept = default;

ImageFileContent& operator=(ImageFileContent&&) noexcept = default;

ImageFileContent(const ImageFileContent&) = delete;

ImageFileContent& operator=(const ImageFileContent&) = delete;

ImageFile image_file;

static cpp::result<ImageFileContent, std::string> FromJson(
Expand All @@ -27,9 +45,9 @@ struct ImageFileContent : Content {
try {
ImageFileContent content;
ImageFile image_file;
image_file.detail = json["image_file"]["detail"].asString();
image_file.file_id = json["image_file"]["file_id"].asString();
content.image_file = image_file;
image_file.detail = std::move(json["image_file"]["detail"].asString());
image_file.file_id = std::move(json["image_file"]["file_id"].asString());
content.image_file = std::move(image_file);
return content;
} catch (const std::exception& e) {
return cpp::fail(std::string("FromJson failed: ") + e.what());
Expand Down
24 changes: 21 additions & 3 deletions engine/common/message_content_image_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ struct ImageUrl {

// Specifies the detail level of the image. low uses fewer tokens, you can opt in to high resolution using high. Default value is auto
std::string detail;

ImageUrl() = default;

ImageUrl(ImageUrl&&) noexcept = default;

ImageUrl& operator=(ImageUrl&&) noexcept = default;

ImageUrl(const ImageUrl&) = delete;

ImageUrl& operator=(const ImageUrl&) = delete;
};

// References an image URL in the content of a message.
Expand All @@ -18,6 +28,14 @@ struct ImageUrlContent : Content {
// The type of the content part.
ImageUrlContent(const std::string& type) : Content(type) {}

ImageUrlContent(ImageUrlContent&&) noexcept = default;

ImageUrlContent& operator=(ImageUrlContent&&) noexcept = default;

ImageUrlContent(const ImageUrlContent&) = delete;

ImageUrlContent& operator=(const ImageUrlContent&) = delete;

ImageUrl image_url;

static cpp::result<ImageUrlContent, std::string> FromJson(
Expand All @@ -29,9 +47,9 @@ struct ImageUrlContent : Content {
try {
ImageUrlContent content{"image_url"};
ImageUrl image_url;
image_url.url = json["image_url"]["url"].asString();
image_url.detail = json["image_url"]["detail"].asString();
content.image_url = image_url;
image_url.url = std::move(json["image_url"]["url"].asString());
image_url.detail = std::move(json["image_url"]["detail"].asString());
content.image_url = std::move(image_url);
return content;
} catch (const std::exception& e) {
return cpp::fail(std::string("FromJson failed: ") + e.what());
Expand Down
13 changes: 10 additions & 3 deletions engine/common/message_content_refusal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ namespace ThreadMessage {
struct Refusal : Content {

// Always refusal.
Refusal() : Content("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;

Expand All @@ -17,8 +25,7 @@ struct Refusal : Content {
}

try {
Refusal content;
content.refusal = json["refusal"].asString();
Refusal content{std::move(json["refusal"].asString())};
return content;
} catch (const std::exception& e) {
return cpp::fail(std::string("FromJson failed: ") + e.what());
Expand Down
69 changes: 62 additions & 7 deletions engine/common/message_content_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,27 @@ struct FileCitationWrapper : Annotation {
uint32_t end_index)
: Annotation("file_citation", text, start_index, end_index) {}

FileCitationWrapper(FileCitationWrapper&&) noexcept = default;

FileCitationWrapper& operator=(FileCitationWrapper&&) noexcept = default;

FileCitationWrapper(const FileCitationWrapper&) = delete;

FileCitationWrapper& operator=(const FileCitationWrapper&) = delete;

struct FileCitation {
// The ID of the specific File the citation is from.
std::string file_id;

FileCitation() = default;

FileCitation(FileCitation&&) noexcept = default;

FileCitation& operator=(FileCitation&&) noexcept = default;

FileCitation(const FileCitation&) = delete;

FileCitation& operator=(const FileCitation&) = delete;
};

FileCitation file_citation;
Expand All @@ -62,9 +80,27 @@ struct FilePathWrapper : Annotation {
uint32_t end_index)
: Annotation("file_path", text, start_index, end_index) {}

FilePathWrapper(FilePathWrapper&&) noexcept = default;

FilePathWrapper& operator=(FilePathWrapper&&) noexcept = default;

FilePathWrapper(const FilePathWrapper&) = delete;

FilePathWrapper& operator=(const FilePathWrapper&) = delete;

struct FilePath {
// The ID of the file that was generated.
std::string file_id;

FilePath() = default;

FilePath(FilePath&&) noexcept = default;

FilePath& operator=(FilePath&&) noexcept = default;

FilePath(const FilePath&) = delete;

FilePath& operator=(const FilePath&) = delete;
};

FilePath file_path;
Expand All @@ -86,6 +122,17 @@ struct FilePathWrapper : Annotation {

struct Text : JsonSerializable {
// The data that makes up the text.

Text() = default;

Text(Text&&) noexcept = default;

Text& operator=(Text&&) noexcept = default;

Text(const Text&) = delete;

Text& operator=(const Text&) = delete;

std::string value;

std::vector<std::unique_ptr<Annotation>> annotations;
Expand All @@ -102,22 +149,23 @@ struct Text : JsonSerializable {
// Parse annotations array
if (json.isMember("annotations") && json["annotations"].isArray()) {
for (const auto& annotation_json : json["annotations"]) {
std::string type = annotation_json["type"].asString();
std::string annotation_text = annotation_json["text"].asString();
std::string type = std::move(annotation_json["type"].asString());
std::string annotation_text =
std::move(annotation_json["text"].asString());
uint32_t start_index = annotation_json["start_index"].asUInt();
uint32_t end_index = annotation_json["end_index"].asUInt();

if (type == "file_citation") {
auto citation = std::make_unique<FileCitationWrapper>(
annotation_text, start_index, end_index);
citation->file_citation.file_id =
annotation_json["file_citation"]["file_id"].asString();
citation->file_citation.file_id = std::move(
annotation_json["file_citation"]["file_id"].asString());
text.annotations.push_back(std::move(citation));
} else if (type == "file_path") {
auto file_path = std::make_unique<FilePathWrapper>(
annotation_text, start_index, end_index);
file_path->file_path.file_id =
annotation_json["file_path"]["file_id"].asString();
std::move(annotation_json["file_path"]["file_id"].asString());
text.annotations.push_back(std::move(file_path));
} else {
CTL_WRN("Unknown annotation type: " + type);
Expand Down Expand Up @@ -156,6 +204,14 @@ struct TextContent : Content {
// Always text.
TextContent() : Content("text") {}

TextContent(TextContent&&) noexcept = default;

TextContent& operator=(TextContent&&) noexcept = default;

TextContent(const TextContent&) = delete;

TextContent& operator=(const TextContent&) = delete;

Text text;

static cpp::result<TextContent, std::string> FromJson(Json::Value&& json) {
Expand All @@ -165,8 +221,7 @@ struct TextContent : Content {

try {
TextContent content;
content.type = json["type"].asString();
content.text = Text::FromJson(std::move(json["text"])).value();
content.text = std::move(Text::FromJson(std::move(json["text"])).value());
return content;
} catch (const std::exception& e) {
return cpp::fail(std::string("FromJson failed: ") + e.what());
Expand Down

0 comments on commit 2578833

Please sign in to comment.