namespace AIStudio.Chat;
///
/// A block of content in a chat thread. Might be any type of content, e.g., text, image, voice, etc.
///
public class ContentBlock
{
///
/// Time when the content block was created.
///
public DateTimeOffset Time { get; init; }
///
/// Type of the content block, e.g., text, image, voice, etc.
///
public ContentType ContentType { get; init; } = ContentType.NONE;
///
/// The content of the block.
///
public IContent? Content { get; set; }
///
/// The role of the content block in the chat thread, e.g., user, AI, etc.
///
public ChatRole Role { get; set; } = ChatRole.NONE;
///
/// Should the content block be hidden from the user?
///
public bool HideFromUser { get; init; }
public ContentBlock DeepClone(bool changeHideState = false, bool hideFromUser = true) => new()
{
Time = this.Time,
ContentType = this.ContentType,
Content = this.Content?.DeepClone(),
Role = this.Role,
HideFromUser = changeHideState ? hideFromUser : this.HideFromUser,
};
///
/// Clones this block for a place apart from its chat, e.g., the example conversation of a chat template.
///
///
/// 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.
///
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;
}
}