mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-10-08 19:40:21 +00:00
Refactor Sources property to use ISource interface instead of Source class
This commit is contained in:
parent
2836e76f20
commit
2946851270
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user