Files
AI-Studio/app/MindWork AI Studio/Chat/ContentImage.cs
T

85 lines
2.4 KiB
C#
Raw Normal View History

2024-07-13 10:37:57 +02:00
using System.Text.Json.Serialization;
2024-05-04 11:11:09 +02:00
using AIStudio.Provider;
2025-12-17 11:33:08 +01:00
using AIStudio.Tools.Validation;
2024-05-04 11:11:09 +02:00
namespace AIStudio.Chat;
/// <summary>
/// Represents an image inside the chat.
/// </summary>
public sealed class ContentImage : IContent, IImageSource
2024-05-04 11:11:09 +02:00
{
#region Implementation of IContent
/// <inheritdoc />
2024-07-13 10:37:57 +02:00
[JsonIgnore]
2025-05-24 19:11:28 +02:00
public bool InitialRemoteWait { get; set; }
2024-05-04 11:11:09 +02:00
/// <inheritdoc />
2024-07-13 10:37:57 +02:00
[JsonIgnore]
2025-05-24 19:11:28 +02:00
public bool IsStreaming { get; set; }
2024-05-04 11:11:09 +02:00
/// <inheritdoc />
2024-07-13 10:37:57 +02:00
[JsonIgnore]
public Func<Task> StreamingDone { get; set; } = IContent.NO_STREAMING_HANDLER;
2024-05-04 11:11:09 +02:00
/// <inheritdoc />
2024-07-13 10:37:57 +02:00
[JsonIgnore]
public Func<Task> StreamingEvent { get; set; } = IContent.NO_STREAMING_HANDLER;
2024-05-04 11:11:09 +02:00
2025-08-31 14:27:35 +02:00
/// <inheritdoc />
public List<Source> Sources { get; set; } = [];
/// <inheritdoc />
2025-12-28 16:50:36 +01:00
public List<FileAttachment> FileAttachments { get; set; } = [];
2024-05-04 11:11:09 +02:00
/// <inheritdoc />
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastUserPrompt, ChatThread? chatChatThread, CancellationToken token = default)
2024-05-04 11:11:09 +02:00
{
throw new NotImplementedException();
}
2025-05-24 12:27:00 +02:00
/// <inheritdoc />
2025-05-24 19:11:28 +02:00
public IContent DeepClone() => new ContentImage
2025-05-24 12:27:00 +02:00
{
2025-05-24 19:11:28 +02:00
Source = this.Source,
InitialRemoteWait = this.InitialRemoteWait,
IsStreaming = this.IsStreaming,
SourceType = this.SourceType,
2025-12-30 18:30:32 +01:00
Sources = [..this.Sources],
FileAttachments = [..this.FileAttachments],
2025-05-24 19:11:28 +02:00
};
2024-05-04 11:11:09 +02:00
#endregion
2025-12-17 11:33:08 +01:00
/// <summary>
/// Creates a ContentImage from a local file path.
/// </summary>
/// <param name="filePath">The path to the image file.</param>
/// <returns>A new ContentImage instance if the file is valid, null otherwise.</returns>
public static async Task<ContentImage?> CreateFromFileAsync(string filePath)
{
if (!await FileExtensionValidation.IsImageExtensionValidWithNotifyAsync(filePath))
return null;
return new ContentImage
{
SourceType = ContentImageSource.LOCAL_PATH,
Source = filePath,
};
}
2024-05-04 11:11:09 +02:00
/// <summary>
2025-02-10 18:49:22 +01:00
/// The type of the image source.
2024-05-04 11:11:09 +02:00
/// </summary>
2025-02-10 18:49:22 +01:00
/// <remarks>
/// Is the image source a URL, a local file path, a base64 string, etc.?
/// </remarks>
public required ContentImageSource SourceType { get; init; }
2024-05-04 11:11:09 +02:00
/// <summary>
2025-02-10 18:49:22 +01:00
/// The image source.
2024-05-04 11:11:09 +02:00
/// </summary>
2025-02-10 18:49:22 +01:00
public required string Source { get; set; }
2024-05-04 11:11:09 +02:00
}