mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-08 06:29:39 +00:00
Added tool calling support (#731)
Co-authored-by: krut_ni <nils.kruthoff@dlr.de> Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
266 files changed
+11186
-740
No files matched your search
@@ -88,6 +88,7 @@ public static partial class SourceExtensions
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var ragSources = new List<ISource>();
|
||||
var toolSources = new List<ISource>();
|
||||
var sourceNum = 0;
|
||||
var addedLLMHeaders = false;
|
||||
foreach (var source in sources)
|
||||
@@ -110,38 +111,82 @@ public static partial class SourceExtensions
|
||||
AppendMarkdownLink(sb, source.Title, source.URL);
|
||||
sb.AppendLine();
|
||||
break;
|
||||
|
||||
case SourceOrigin.TOOL:
|
||||
toolSources.Add(source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ragSources.Count == 0)
|
||||
return sb.ToString();
|
||||
|
||||
sb.AppendLine();
|
||||
sb.Append("## ");
|
||||
sb.AppendLine(TB("Sources provided by the data providers"));
|
||||
|
||||
foreach (var source in ragSources)
|
||||
|
||||
if(toolSources.Count > 0)
|
||||
{
|
||||
sb.Append($"- [{++sourceNum}] ");
|
||||
AppendMarkdownLink(sb, source.Title, source.URL);
|
||||
sb.AppendLine();
|
||||
if(sb.Length > 0)
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("## ");
|
||||
sb.AppendLine(TB("Sources used by tools"));
|
||||
|
||||
foreach (var source in toolSources)
|
||||
{
|
||||
sb.Append($"- [{++sourceNum}] ");
|
||||
AppendMarkdownLink(sb, source.Title, source.URL);
|
||||
sb.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ragSources.Count > 0)
|
||||
{
|
||||
if(sb.Length > 0)
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("## ");
|
||||
sb.AppendLine(TB("Sources provided by the data providers"));
|
||||
|
||||
foreach (var source in ragSources)
|
||||
{
|
||||
sb.Append($"- [{++sourceNum}] ");
|
||||
AppendMarkdownLink(sb, source.Title, source.URL);
|
||||
sb.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Merges a list of added sources into an existing list of sources, avoiding duplicates based on URL and Title.
|
||||
/// Merges a list of added sources into an existing list of sources, avoiding duplicates based on normalized URLs.
|
||||
/// </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<Source> sources, IEnumerable<ISource> addedSources)
|
||||
{
|
||||
var sourceIdentities = sources
|
||||
.Select(source => GetSourceIdentity(source.URL))
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
foreach (var addedSource in addedSources)
|
||||
if (sources.All(s => s.URL != addedSource.URL && s.Title != addedSource.Title))
|
||||
{
|
||||
if (sourceIdentities.Add(GetSourceIdentity(addedSource.URL)))
|
||||
sources.Add((Source)addedSource);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSourceIdentity(string url)
|
||||
{
|
||||
var cleanedUrl = url.Trim().Replace("\r", string.Empty).Replace("\n", string.Empty);
|
||||
if (!Uri.TryCreate(cleanedUrl, UriKind.Absolute, out var absoluteUri))
|
||||
return cleanedUrl;
|
||||
|
||||
var normalizedUri = new UriBuilder(absoluteUri)
|
||||
{
|
||||
Scheme = absoluteUri.Scheme.ToLowerInvariant(),
|
||||
Host = absoluteUri.IdnHost.TrimEnd('.').ToLowerInvariant(),
|
||||
Port = absoluteUri.IsDefaultPort ? -1 : absoluteUri.Port,
|
||||
Fragment = string.Empty,
|
||||
};
|
||||
return normalizedUri.Uri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^\[(?<label>[^\]]+)\]\((?<url>[^)\r\n]+)\)(?<suffix>.*)$")]
|
||||
private static partial Regex MarkdownLinkWithOptionalSuffix();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user