using System.Text.Json.Serialization; using AIStudio.Provider; using AIStudio.Tools.Validation; namespace AIStudio.Chat; /// /// Represents an image inside the chat. /// public sealed class ContentImage : IContent, IImageSource { #region Implementation of IContent /// [JsonIgnore] public bool InitialRemoteWait { get; set; } /// [JsonIgnore] public bool IsStreaming { get; set; } /// [JsonIgnore] public Func StreamingDone { get; set; } = () => Task.CompletedTask; /// [JsonIgnore] public Func StreamingEvent { get; set; } = () => Task.CompletedTask; /// public List Sources { get; set; } = []; /// public List FileAttachments { get; set; } = []; /// public Task CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastUserPrompt, ChatThread? chatChatThread, CancellationToken token = default) { throw new NotImplementedException(); } /// public IContent DeepClone() => new ContentImage { Source = this.Source, InitialRemoteWait = this.InitialRemoteWait, IsStreaming = this.IsStreaming, SourceType = this.SourceType, }; #endregion /// /// Creates a ContentImage from a local file path. /// /// The path to the image file. /// A new ContentImage instance if the file is valid, null otherwise. public static async Task CreateFromFileAsync(string filePath) { if (!await FileExtensionValidation.IsImageExtensionValidWithNotifyAsync(filePath)) return null; return new ContentImage { SourceType = ContentImageSource.LOCAL_PATH, Source = filePath, }; } /// /// The type of the image source. /// /// /// Is the image source a URL, a local file path, a base64 string, etc.? /// public required ContentImageSource SourceType { get; init; } /// /// The image source. /// public required string Source { get; set; } }