Refactor Sources property to use ISource interface instead of Source class

This commit is contained in:
Thorsten Sommer 2025-09-24 11:29:38 +02:00
parent 2836e76f20
commit 2946851270
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 6 additions and 6 deletions

View File

@ -28,7 +28,7 @@ public sealed class ContentImage : IContent, IImageSource
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
/// <inheritdoc />
public List<Source> Sources { get; set; } = [];
public List<ISource> Sources { get; set; } = [];
/// <inheritdoc />
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default)

View File

@ -38,7 +38,7 @@ public sealed class ContentText : IContent
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
/// <inheritdoc />
public List<Source> Sources { get; set; } = [];
public List<ISource> Sources { get; set; } = [];
/// <inheritdoc />
public async Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatThread, CancellationToken token = default)

View File

@ -42,7 +42,7 @@ public interface IContent
/// The provided sources, if any.
/// </summary>
[JsonIgnore]
public List<Source> Sources { get; set; }
public List<ISource> Sources { get; set; }
/// <summary>
/// Uses the provider to create the content.

View File

@ -13,7 +13,7 @@ public static class SourceExtensions
/// </summary>
/// <param name="sources">The list of sources to convert.</param>
/// <returns>A markdown-formatted string representing the sources.</returns>
public static string ToMarkdown(this IList<Source> sources)
public static string ToMarkdown(this IList<ISource> sources)
{
var sb = new StringBuilder();
sb.Append("## ");
@ -38,10 +38,10 @@ public static class SourceExtensions
/// </summary>
/// <param name="sources">The existing list of sources to merge into.</param>
/// <param name="addedSources">The list of sources to add.</param>
public static void MergeSources(this IList<Source> sources, IList<ISource> addedSources)
public static void MergeSources(this IList<ISource> sources, IList<ISource> addedSources)
{
foreach (var addedSource in addedSources)
if (sources.All(s => s.URL != addedSource.URL && s.Title != addedSource.Title))
sources.Add((Source)addedSource);
sources.Add(addedSource);
}
}