mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-04 21:29:40 +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
@@ -0,0 +1,60 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
namespace AIStudio.Tools.ToolCallingSystem;
|
||||
|
||||
public interface IToolImplementation
|
||||
{
|
||||
public string ImplementationKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Describes this tool: what the model may call, which settings it needs, and where it may
|
||||
/// be used.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For a tool written in C#, the definition and the implementation are one object. Tools that
|
||||
/// arrive from elsewhere — a plugin, an assistant — get their definition from their own
|
||||
/// definition source instead, and are matched to an implementation by their implementation key.
|
||||
/// </remarks>
|
||||
public ToolDefinition GetDefinition();
|
||||
|
||||
public string Icon => Icons.Material.Filled.Build;
|
||||
|
||||
public IReadOnlySet<string> SensitiveTraceArgumentNames { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this tool returns content it fetched from outside AI Studio, such as a web page.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Such content is attacker-controlled and must be filtered for prompt injections before a
|
||||
/// model sees it. A tool that returns it filters it itself, because only the tool knows which
|
||||
/// of its fields came from where — see the web search and read web page tools, which do so
|
||||
/// through the web page content sanitizer.<br/><br/>
|
||||
/// Declaring it here keeps the obligation visible in one place, and gives tools that cannot
|
||||
/// carry it out themselves, such as tools defined by plugin authors, a flag the tool executor
|
||||
/// can act on for them.
|
||||
/// </remarks>
|
||||
public bool ReturnsUntrustedExternalContent => false;
|
||||
|
||||
public string GetDisplayName() => TB("Tool");
|
||||
|
||||
public string GetDescription() => TB("Tool description");
|
||||
|
||||
public string GetSettingsFieldLabel(string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
|
||||
TB(fieldDefinition.Title);
|
||||
|
||||
public string GetSettingsFieldDescription(string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
|
||||
TB(fieldDefinition.Description);
|
||||
|
||||
public string? GetSettingsFieldDefaultValue(string fieldName, ToolSettingsFieldDefinition fieldDefinition) => null;
|
||||
|
||||
public Task<ToolConfigurationState?> ValidateConfigurationAsync(
|
||||
ToolDefinition definition,
|
||||
IReadOnlyDictionary<string, string> settingsValues,
|
||||
CancellationToken token = default) => Task.FromResult<ToolConfigurationState?>(null);
|
||||
|
||||
public Task<ToolExecutionResult> ExecuteAsync(JsonElement arguments, ToolExecutionContext context, CancellationToken token = default);
|
||||
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(IToolImplementation).Namespace, nameof(IToolImplementation));
|
||||
}
|
||||
Reference in new issue
Block a user