mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-05 04:47:21 +00:00
Moved all extension methods into extension blocks (#1155)
This commit is contained in:
1 parent
acc7d09fa2
commit
c0a75f39ac
138 files changed
+5884
-4954
No files matched your search
@@ -2,29 +2,32 @@ namespace AIStudio.Tools.ToolCallingSystem;
|
||||
|
||||
public static class SafeSearchPolicyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The value SearXNG expects for its safesearch parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// SearXNG takes the level as a number. That number stays here, at the edge towards the
|
||||
/// search engine, instead of travelling through the settings where nobody can read it.
|
||||
/// </remarks>
|
||||
public static string ToSearXNGValue(this SafeSearchPolicy policy) => policy switch
|
||||
extension(SafeSearchPolicy policy)
|
||||
{
|
||||
SafeSearchPolicy.OFF => "0",
|
||||
SafeSearchPolicy.MODERATE => "1",
|
||||
SafeSearchPolicy.STRICT => "2",
|
||||
/// <summary>
|
||||
/// The value SearXNG expects for its safesearch parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// SearXNG takes the level as a number. That number stays here, at the edge towards the
|
||||
/// search engine, instead of travelling through the settings where nobody can read it.
|
||||
/// </remarks>
|
||||
public string ToSearXNGValue() => policy switch
|
||||
{
|
||||
SafeSearchPolicy.OFF => "0",
|
||||
SafeSearchPolicy.MODERATE => "1",
|
||||
SafeSearchPolicy.STRICT => "2",
|
||||
|
||||
_ => "0",
|
||||
};
|
||||
_ => "0",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The value Tavily expects for its safe search parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Tavily knows filtering only as on or off, so a moderate policy is filtered as strictly as
|
||||
/// a strict one. Of the two ways to round that, filtering more than was asked for is the one
|
||||
/// that cannot surprise anyone.
|
||||
/// </remarks>
|
||||
public static bool ToTavilyValue(this SafeSearchPolicy policy) => policy is not SafeSearchPolicy.OFF;
|
||||
/// <summary>
|
||||
/// The value Tavily expects for its safe search parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Tavily knows filtering only as on or off, so a moderate policy is filtered as strictly as
|
||||
/// a strict one. Of the two ways to round that, filtering more than was asked for is the one
|
||||
/// that cannot surprise anyone.
|
||||
/// </remarks>
|
||||
public bool ToTavilyValue() => policy is not SafeSearchPolicy.OFF;
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -8,17 +8,20 @@ public static class ToolCallingAvailabilityExtensions
|
||||
{
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ToolCallingAvailabilityExtensions).Namespace, nameof(ToolCallingAvailabilityExtensions));
|
||||
|
||||
public static ToolCallingAvailability GetToolCallingAvailability(this AIStudio.Settings.Provider provider)
|
||||
extension(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if (provider == AIStudio.Settings.Provider.NONE || provider.UsedLLMProvider is LLMProviders.NONE)
|
||||
return new(false, TB("Please select an LLM provider."));
|
||||
public ToolCallingAvailability GetToolCallingAvailability()
|
||||
{
|
||||
if (provider == AIStudio.Settings.Provider.NONE || provider.UsedLLMProvider is LLMProviders.NONE)
|
||||
return new(false, TB("Please select an LLM provider."));
|
||||
|
||||
var modelProfile = provider.GetModelProfile();
|
||||
var supportsRequiredApis = modelProfile.HasAny(Capability.CHAT_COMPLETION_API | Capability.RESPONSES_API);
|
||||
var modelProfile = provider.GetModelProfile();
|
||||
var supportsRequiredApis = modelProfile.HasAny(Capability.CHAT_COMPLETION_API | Capability.RESPONSES_API);
|
||||
|
||||
if (!supportsRequiredApis || !modelProfile.Has(Capability.FUNCTION_CALLING))
|
||||
return new(false, TB("Tool calling support is not enabled by default for this model, but you can enable this capability in the expert settings of the provider if you are sure the model supports it."));
|
||||
if (!supportsRequiredApis || !modelProfile.Has(Capability.FUNCTION_CALLING))
|
||||
return new(false, TB("Tool calling support is not enabled by default for this model, but you can enable this capability in the expert settings of the provider if you are sure the model supports it."));
|
||||
|
||||
return ToolCallingAvailability.Available();
|
||||
return ToolCallingAvailability.Available();
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -56,6 +56,12 @@ internal static class MailToolArguments
|
||||
/// <param name="toolAction">What the tool does with the mails, e.g., "search", completing "the mailboxes to ...".</param>
|
||||
/// <param name="mailboxIds">The ids of the mailboxes the tool offers, or none while no mailboxes are known.</param>
|
||||
/// <returns>The schema, for further arguments.</returns>
|
||||
/// <remarks>
|
||||
/// A classic extension method instead of a member of an extension block: for those, the compiler of
|
||||
/// the .NET 10.0.1xx SDK warns about every mailbox id passed one by one to the params parameter
|
||||
/// (CS8620, dotnet/roslyn#80024). Move it once the SDK in metadata.txt carries the fix; MWAIS0016 makes
|
||||
/// the same exception until then.
|
||||
/// </remarks>
|
||||
public static ToolParameterSchemaBuilder AddMailConditions(this ToolParameterSchemaBuilder builder, string toolAction, params string[] mailboxIds) => builder
|
||||
.OptionalStringArray(MAILBOX_IDS_ARGUMENT, $"Optional IDs of the mailboxes to {toolAction}, out of those listed in the description of this tool. Leave it out to {toolAction} all of them.", mailboxIds)
|
||||
.OptionalString(FROM_ARGUMENT, $"Optional part of the address or the name of the sender, such as 'alice@example.org', 'example.org', or 'Alice'. At most {MAX_ADDRESS_CHARACTERS} characters.")
|
||||
|
||||
+18
-15
@@ -2,21 +2,24 @@ namespace AIStudio.Tools.ToolCallingSystem.ToolCallingImplementations.WebSearch;
|
||||
|
||||
public static class WebSearchBackendExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of one search service, as the user reads it and as a search result reports it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Product names, so they are not translated: SearXNG is called SearXNG in every language.
|
||||
/// What gets stored is the enum member name instead, which is what leaves this free to be
|
||||
/// worded for people — in the settings dropdown, in a note explaining which service
|
||||
/// answered, and in the result the model reads.
|
||||
/// </remarks>
|
||||
public static string ToName(this WebSearchBackend backend) => backend switch
|
||||
extension(WebSearchBackend backend)
|
||||
{
|
||||
WebSearchBackend.SEARXNG => "SearXNG",
|
||||
WebSearchBackend.STAAN => "Staan",
|
||||
WebSearchBackend.TAVILY => "Tavily",
|
||||
/// <summary>
|
||||
/// The name of one search service, as the user reads it and as a search result reports it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Product names, so they are not translated: SearXNG is called SearXNG in every language.
|
||||
/// What gets stored is the enum member name instead, which is what leaves this free to be
|
||||
/// worded for people — in the settings dropdown, in a note explaining which service
|
||||
/// answered, and in the result the model reads.
|
||||
/// </remarks>
|
||||
public string ToName() => backend switch
|
||||
{
|
||||
WebSearchBackend.SEARXNG => "SearXNG",
|
||||
WebSearchBackend.STAAN => "Staan",
|
||||
WebSearchBackend.TAVILY => "Tavily",
|
||||
|
||||
_ => backend.ToString(),
|
||||
};
|
||||
_ => backend.ToString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user