2024-05-04 11:11:09 +02:00
|
|
|
namespace AIStudio.Chat;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A block of content in a chat thread. Might be any type of content, e.g., text, image, voice, etc.
|
|
|
|
|
/// </summary>
|
2024-07-13 10:37:57 +02:00
|
|
|
public class ContentBlock
|
2024-05-04 11:11:09 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time when the content block was created.
|
|
|
|
|
/// </summary>
|
2024-07-13 10:37:57 +02:00
|
|
|
public DateTimeOffset Time { get; init; }
|
2024-05-04 11:11:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Type of the content block, e.g., text, image, voice, etc.
|
|
|
|
|
/// </summary>
|
2024-07-13 10:37:57 +02:00
|
|
|
public ContentType ContentType { get; init; } = ContentType.NONE;
|
2024-05-04 11:11:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The content of the block.
|
|
|
|
|
/// </summary>
|
2025-05-24 12:27:00 +02:00
|
|
|
public IContent? Content { get; set; }
|
2024-05-04 11:11:09 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The role of the content block in the chat thread, e.g., user, AI, etc.
|
|
|
|
|
/// </summary>
|
2025-05-24 12:27:00 +02:00
|
|
|
public ChatRole Role { get; set; } = ChatRole.NONE;
|
2024-10-28 15:41:00 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should the content block be hidden from the user?
|
|
|
|
|
/// </summary>
|
2025-05-24 19:11:28 +02:00
|
|
|
public bool HideFromUser { get; init; }
|
2025-05-24 12:27:00 +02:00
|
|
|
|
2025-07-11 09:57:46 +02:00
|
|
|
public ContentBlock DeepClone(bool changeHideState = false, bool hideFromUser = true) => new()
|
2025-05-24 12:27:00 +02:00
|
|
|
{
|
2025-05-24 19:11:28 +02:00
|
|
|
Time = this.Time,
|
|
|
|
|
ContentType = this.ContentType,
|
|
|
|
|
Content = this.Content?.DeepClone(),
|
|
|
|
|
Role = this.Role,
|
2025-07-11 09:57:46 +02:00
|
|
|
HideFromUser = changeHideState ? hideFromUser : this.HideFromUser,
|
2025-05-24 19:11:28 +02:00
|
|
|
};
|
2026-10-26 10:00:01 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clones this block for a place apart from its chat, e.g., the example conversation of a chat template.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Without anything which refers to the provenance store: its entries belong to the chat and are
|
|
|
|
|
/// deleted with it. The passages of an answer stay behind, and every chat which receives an
|
|
|
|
|
/// attached document reads it anew from its file, cf. FileAttachment.ProvenanceId.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public ContentBlock CloneApartFromChat(bool changeHideState = false, bool hideFromUser = true)
|
|
|
|
|
{
|
|
|
|
|
var clone = this.DeepClone(changeHideState, hideFromUser);
|
|
|
|
|
if (clone.Content is ContentText text)
|
|
|
|
|
text.SourcePassages = [];
|
|
|
|
|
|
|
|
|
|
if (clone.Content is not null)
|
|
|
|
|
clone.Content.FileAttachments = clone.Content.FileAttachments.Select(attachment => attachment.WithoutStoredText()).ToList();
|
|
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
|
}
|
2024-05-04 11:11:09 +02:00
|
|
|
}
|