mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-11-23 13:50:20 +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;
|
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<Source> Sources { get; set; } = [];
|
public List<ISource> Sources { get; set; } = [];
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default)
|
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;
|
public Func<Task> StreamingEvent { get; set; } = () => Task.CompletedTask;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<Source> Sources { get; set; } = [];
|
public List<ISource> Sources { get; set; } = [];
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatThread, CancellationToken token = default)
|
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.
|
/// The provided sources, if any.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public List<Source> Sources { get; set; }
|
public List<ISource> Sources { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uses the provider to create the content.
|
/// Uses the provider to create the content.
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public static class SourceExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sources">The list of sources to convert.</param>
|
/// <param name="sources">The list of sources to convert.</param>
|
||||||
/// <returns>A markdown-formatted string representing the sources.</returns>
|
/// <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();
|
var sb = new StringBuilder();
|
||||||
sb.Append("## ");
|
sb.Append("## ");
|
||||||
@ -38,10 +38,10 @@ public static class SourceExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sources">The existing list of sources to merge into.</param>
|
/// <param name="sources">The existing list of sources to merge into.</param>
|
||||||
/// <param name="addedSources">The list of sources to add.</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)
|
foreach (var addedSource in addedSources)
|
||||||
if (sources.All(s => s.URL != addedSource.URL && s.Title != addedSource.Title))
|
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