-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1382 from solliancenet/kb-message-content-items-c…
…herry-pick-080 Add message content items - cherry pick into 0.8.0
- Loading branch information
Showing
8 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/dotnet/Common/Constants/Orchestration/MessageContentItemTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace FoundationaLLM.Common.Constants.Orchestration | ||
{ | ||
/// <summary> | ||
/// Contains constants for the types of message content items. | ||
/// </summary> | ||
public static class MessageContentItemTypes | ||
{ | ||
/// <summary> | ||
/// Text content. | ||
/// </summary> | ||
public const string Text = "text"; | ||
|
||
/// <summary> | ||
/// Image file content. | ||
/// </summary> | ||
public const string ImageFile = "image_file"; | ||
|
||
/// <summary> | ||
/// File path content. | ||
/// </summary> | ||
public const string FilePath = "file_path"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace FoundationaLLM.Common.Models.Chat | ||
{ | ||
/// <summary> | ||
/// Contains parts that compose the message content. | ||
/// </summary> | ||
public class MessageContent | ||
{ | ||
/// <summary> | ||
/// The type of the message content. Could be text, image, etc. | ||
/// </summary> | ||
[JsonPropertyName("type")] | ||
public string? Type { get; set; } | ||
|
||
/// <summary> | ||
/// The value of the message content. | ||
/// </summary> | ||
[JsonPropertyName("value")] | ||
public string? Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/dotnet/Common/Models/Orchestration/MessageContentItemBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using FoundationaLLM.Common.Constants.Orchestration; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace FoundationaLLM.Common.Models.Orchestration | ||
{ | ||
/// <summary> | ||
/// Base message content item model. | ||
/// </summary> | ||
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] | ||
[JsonDerivedType(typeof(OpenAITextMessageContentItem), MessageContentItemTypes.Text)] | ||
[JsonDerivedType(typeof(OpenAIImageFileMessageContentItem), MessageContentItemTypes.ImageFile)] | ||
[JsonDerivedType(typeof(OpenAIFilePathContentItem), MessageContentItemTypes.FilePath)] | ||
public class MessageContentItemBase | ||
{ | ||
/// <summary> | ||
/// The type of the message content item. | ||
/// </summary> | ||
[JsonPropertyName("type")] | ||
[JsonPropertyOrder(-100)] | ||
public virtual string? Type { get; set; } | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/dotnet/Common/Models/Orchestration/OpenAIFilePathContentItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using FoundationaLLM.Common.Constants.Orchestration; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace FoundationaLLM.Common.Models.Orchestration | ||
{ | ||
/// <summary> | ||
/// File content item used to generate a message content item. | ||
/// </summary> | ||
public class OpenAIFilePathContentItem : MessageContentItemBase | ||
{ | ||
/// <inheritdoc/> | ||
[JsonIgnore] | ||
public override string? Type { get; set; } | ||
|
||
/// <summary> | ||
/// The text of the annotation. | ||
/// </summary> | ||
[JsonPropertyName("text")] | ||
public string? Text { get; set; } | ||
|
||
/// <summary> | ||
/// The starting index of the annotation. | ||
/// </summary> | ||
[JsonPropertyName("start_index")] | ||
public int? StartIndex { get; set; } | ||
|
||
/// <summary> | ||
/// The ending index of the annotation. | ||
/// </summary> | ||
[JsonPropertyName("end_index")] | ||
public int? EndIndex { get; set; } | ||
|
||
/// <summary> | ||
/// The ID of the file referenced by the annotation. | ||
/// </summary> | ||
[JsonPropertyName("file_id")] | ||
public string? FileId { get; set; } | ||
|
||
/// <summary> | ||
/// Set default property values. | ||
/// </summary> | ||
public OpenAIFilePathContentItem() => | ||
Type = MessageContentItemTypes.FilePath; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/dotnet/Common/Models/Orchestration/OpenAIImageFileMessageContentItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using FoundationaLLM.Common.Constants.Orchestration; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace FoundationaLLM.Common.Models.Orchestration | ||
{ | ||
/// <summary> | ||
/// An OpenAI image file message content item. | ||
/// </summary> | ||
public class OpenAIImageFileMessageContentItem : MessageContentItemBase | ||
{ | ||
/// <inheritdoc/> | ||
[JsonIgnore] | ||
public override string? Type { get; set; } | ||
|
||
/// <summary> | ||
/// The ID of the image file. | ||
/// </summary> | ||
[JsonPropertyName("file_id")] | ||
public string? FileId { get; set; } | ||
|
||
/// <summary> | ||
/// The URL of the image file. | ||
/// </summary> | ||
[JsonPropertyName("file_url")] | ||
public string? FileUrl { get; set; } | ||
|
||
/// <summary> | ||
/// Set default property values. | ||
/// </summary> | ||
public OpenAIImageFileMessageContentItem() => | ||
Type = MessageContentItemTypes.ImageFile; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/dotnet/Common/Models/Orchestration/OpenAITextMessageContentItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using FoundationaLLM.Common.Constants.Orchestration; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace FoundationaLLM.Common.Models.Orchestration | ||
{ | ||
/// <summary> | ||
/// An OpenAI text message content item. | ||
/// </summary> | ||
public class OpenAITextMessageContentItem : MessageContentItemBase | ||
{ | ||
/// <inheritdoc/> | ||
[JsonIgnore] | ||
public override string? Type { get; set; } | ||
|
||
/// <summary> | ||
/// A list of file annotations used to generate the message content item. | ||
/// </summary> | ||
[JsonPropertyName("annotations")] | ||
public List<OpenAIFilePathContentItem> Annotations { get; set; } = []; | ||
|
||
/// <summary> | ||
/// The text value of the message content item. | ||
/// </summary> | ||
[JsonPropertyName("value")] | ||
public string? Value { get; set; } | ||
|
||
/// <summary> | ||
/// Set default property values. | ||
/// </summary> | ||
public OpenAITextMessageContentItem() => | ||
Type = MessageContentItemTypes.Text; | ||
} | ||
} |