From 4f4b85e497f7960c1a69d2560db5d0f8d7d4bfea Mon Sep 17 00:00:00 2001 From: James Date: Sat, 30 Nov 2024 00:09:55 +0700 Subject: [PATCH] fix ci windows Signed-off-by: James --- engine/common/message.h | 19 ++++-- engine/common/message_content.h | 8 +++ engine/common/message_content_image_file.h | 24 +++++++- engine/common/message_content_image_url.h | 24 +++++++- engine/common/message_content_refusal.h | 13 +++- engine/common/message_content_text.h | 69 +++++++++++++++++++--- 6 files changed, 136 insertions(+), 21 deletions(-) diff --git a/engine/common/message.h b/engine/common/message.h index dbc61c6fd..e5685f3bb 100644 --- a/engine/common/message.h +++ b/engine/common/message.h @@ -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; @@ -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(); diff --git a/engine/common/message_content.h b/engine/common/message_content.h index 7f3ec8e59..6e76b01a8 100644 --- a/engine/common/message_content.h +++ b/engine/common/message_content.h @@ -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 diff --git a/engine/common/message_content_image_file.h b/engine/common/message_content_image_file.h index 83cf62b9e..1807dec1e 100644 --- a/engine/common/message_content_image_file.h +++ b/engine/common/message_content_image_file.h @@ -9,6 +9,16 @@ 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. @@ -16,6 +26,14 @@ 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 FromJson( @@ -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()); diff --git a/engine/common/message_content_image_url.h b/engine/common/message_content_image_url.h index f52d299a4..eae6a7aa6 100644 --- a/engine/common/message_content_image_url.h +++ b/engine/common/message_content_image_url.h @@ -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. @@ -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 FromJson( @@ -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()); diff --git a/engine/common/message_content_refusal.h b/engine/common/message_content_refusal.h index 3fb7f78b6..8353c3a85 100644 --- a/engine/common/message_content_refusal.h +++ b/engine/common/message_content_refusal.h @@ -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; @@ -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()); diff --git a/engine/common/message_content_text.h b/engine/common/message_content_text.h index 0704ac7d5..124d4a878 100644 --- a/engine/common/message_content_text.h +++ b/engine/common/message_content_text.h @@ -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; @@ -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; @@ -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> annotations; @@ -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( 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( 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); @@ -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 FromJson(Json::Value&& json) { @@ -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());