diff --git a/src/dotnet/Common/Constants/Orchestration/MessageContentItemTypes.cs b/src/dotnet/Common/Constants/Orchestration/MessageContentItemTypes.cs new file mode 100644 index 0000000000..4317366b6f --- /dev/null +++ b/src/dotnet/Common/Constants/Orchestration/MessageContentItemTypes.cs @@ -0,0 +1,23 @@ +namespace FoundationaLLM.Common.Constants.Orchestration +{ + /// + /// Contains constants for the types of message content items. + /// + public static class MessageContentItemTypes + { + /// + /// Text content. + /// + public const string Text = "text"; + + /// + /// Image file content. + /// + public const string ImageFile = "image_file"; + + /// + /// File path content. + /// + public const string FilePath = "file_path"; + } +} diff --git a/src/dotnet/Common/Models/Chat/Message.cs b/src/dotnet/Common/Models/Chat/Message.cs index a7e730d651..ae7cf53fb5 100644 --- a/src/dotnet/Common/Models/Chat/Message.cs +++ b/src/dotnet/Common/Models/Chat/Message.cs @@ -1,5 +1,6 @@ using Azure.Search.Documents.Indexes; using FoundationaLLM.Common.Models.Orchestration; +using System.Text.Json.Serialization; namespace FoundationaLLM.Common.Models.Chat; @@ -82,12 +83,18 @@ public record Message /// public Citation[]? Citations { get; set; } + /// + /// The content of the message. + /// + [JsonPropertyName("content")] + public List? Content { get; set; } + /// /// Constructor for Message. /// public Message(string sessionId, string sender, int? tokens, string text, float[]? vector, bool? rating, string upn, string? senderDisplayName = null, - Citation[]? citations = null, string? expectedCompletion = null) + Citation[]? citations = null, string? expectedCompletion = null, List? content = null) { Id = Guid.NewGuid().ToString(); Type = nameof(Message); @@ -102,5 +109,6 @@ public Message(string sessionId, string sender, int? tokens, string text, UPN = upn; ExpectedCompletion = expectedCompletion; Citations = citations; + Content = content; } } diff --git a/src/dotnet/Common/Models/Chat/MessageContent.cs b/src/dotnet/Common/Models/Chat/MessageContent.cs new file mode 100644 index 0000000000..81d646862a --- /dev/null +++ b/src/dotnet/Common/Models/Chat/MessageContent.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace FoundationaLLM.Common.Models.Chat +{ + /// + /// Contains parts that compose the message content. + /// + public class MessageContent + { + /// + /// The type of the message content. Could be text, image, etc. + /// + [JsonPropertyName("type")] + public string? Type { get; set; } + + /// + /// The value of the message content. + /// + [JsonPropertyName("value")] + public string? Value { get; set; } + } +} diff --git a/src/dotnet/Common/Models/Orchestration/CompletionResponseBase.cs b/src/dotnet/Common/Models/Orchestration/CompletionResponseBase.cs index 7c4008099b..27196d6d50 100644 --- a/src/dotnet/Common/Models/Orchestration/CompletionResponseBase.cs +++ b/src/dotnet/Common/Models/Orchestration/CompletionResponseBase.cs @@ -19,6 +19,12 @@ public class CompletionResponseBase [JsonPropertyName("completion")] public string Completion { get; set; } + /// + /// Content returned from the Assistants API. + /// + [JsonPropertyName("content")] + public List? Content { get; set; } + /// /// The citations used in building the completion response. /// diff --git a/src/dotnet/Common/Models/Orchestration/MessageContentItemBase.cs b/src/dotnet/Common/Models/Orchestration/MessageContentItemBase.cs new file mode 100644 index 0000000000..2800b645a7 --- /dev/null +++ b/src/dotnet/Common/Models/Orchestration/MessageContentItemBase.cs @@ -0,0 +1,22 @@ +using FoundationaLLM.Common.Constants.Orchestration; +using System.Text.Json.Serialization; + +namespace FoundationaLLM.Common.Models.Orchestration +{ + /// + /// Base message content item model. + /// + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(OpenAITextMessageContentItem), MessageContentItemTypes.Text)] + [JsonDerivedType(typeof(OpenAIImageFileMessageContentItem), MessageContentItemTypes.ImageFile)] + [JsonDerivedType(typeof(OpenAIFilePathContentItem), MessageContentItemTypes.FilePath)] + public class MessageContentItemBase + { + /// + /// The type of the message content item. + /// + [JsonPropertyName("type")] + [JsonPropertyOrder(-100)] + public virtual string? Type { get; set; } + } +} diff --git a/src/dotnet/Common/Models/Orchestration/OpenAIFilePathContentItem.cs b/src/dotnet/Common/Models/Orchestration/OpenAIFilePathContentItem.cs new file mode 100644 index 0000000000..f23cb71090 --- /dev/null +++ b/src/dotnet/Common/Models/Orchestration/OpenAIFilePathContentItem.cs @@ -0,0 +1,45 @@ +using FoundationaLLM.Common.Constants.Orchestration; +using System.Text.Json.Serialization; + +namespace FoundationaLLM.Common.Models.Orchestration +{ + /// + /// File content item used to generate a message content item. + /// + public class OpenAIFilePathContentItem : MessageContentItemBase + { + /// + [JsonIgnore] + public override string? Type { get; set; } + + /// + /// The text of the annotation. + /// + [JsonPropertyName("text")] + public string? Text { get; set; } + + /// + /// The starting index of the annotation. + /// + [JsonPropertyName("start_index")] + public int? StartIndex { get; set; } + + /// + /// The ending index of the annotation. + /// + [JsonPropertyName("end_index")] + public int? EndIndex { get; set; } + + /// + /// The ID of the file referenced by the annotation. + /// + [JsonPropertyName("file_id")] + public string? FileId { get; set; } + + /// + /// Set default property values. + /// + public OpenAIFilePathContentItem() => + Type = MessageContentItemTypes.FilePath; + } +} diff --git a/src/dotnet/Common/Models/Orchestration/OpenAIImageFileMessageContentItem.cs b/src/dotnet/Common/Models/Orchestration/OpenAIImageFileMessageContentItem.cs new file mode 100644 index 0000000000..d322eac2b8 --- /dev/null +++ b/src/dotnet/Common/Models/Orchestration/OpenAIImageFileMessageContentItem.cs @@ -0,0 +1,33 @@ +using FoundationaLLM.Common.Constants.Orchestration; +using System.Text.Json.Serialization; + +namespace FoundationaLLM.Common.Models.Orchestration +{ + /// + /// An OpenAI image file message content item. + /// + public class OpenAIImageFileMessageContentItem : MessageContentItemBase + { + /// + [JsonIgnore] + public override string? Type { get; set; } + + /// + /// The ID of the image file. + /// + [JsonPropertyName("file_id")] + public string? FileId { get; set; } + + /// + /// The URL of the image file. + /// + [JsonPropertyName("file_url")] + public string? FileUrl { get; set; } + + /// + /// Set default property values. + /// + public OpenAIImageFileMessageContentItem() => + Type = MessageContentItemTypes.ImageFile; + } +} diff --git a/src/dotnet/Common/Models/Orchestration/OpenAITextMessageContentItem.cs b/src/dotnet/Common/Models/Orchestration/OpenAITextMessageContentItem.cs new file mode 100644 index 0000000000..cd9cbdd023 --- /dev/null +++ b/src/dotnet/Common/Models/Orchestration/OpenAITextMessageContentItem.cs @@ -0,0 +1,33 @@ +using FoundationaLLM.Common.Constants.Orchestration; +using System.Text.Json.Serialization; + +namespace FoundationaLLM.Common.Models.Orchestration +{ + /// + /// An OpenAI text message content item. + /// + public class OpenAITextMessageContentItem : MessageContentItemBase + { + /// + [JsonIgnore] + public override string? Type { get; set; } + + /// + /// A list of file annotations used to generate the message content item. + /// + [JsonPropertyName("annotations")] + public List Annotations { get; set; } = []; + + /// + /// The text value of the message content item. + /// + [JsonPropertyName("value")] + public string? Value { get; set; } + + /// + /// Set default property values. + /// + public OpenAITextMessageContentItem() => + Type = MessageContentItemTypes.Text; + } +}