mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-05 04:47:21 +00:00
Turned getter-like extension methods into extension properties (#1157)
This commit is contained in:
1 parent
0375318b1b
commit
f649febf88
286 files changed
+1379
-1109
No files matched your search
@@ -11,7 +11,7 @@ public static class SafeSearchPolicyExtensions
|
||||
/// 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
|
||||
public string SearXNGValue => policy switch
|
||||
{
|
||||
SafeSearchPolicy.OFF => "0",
|
||||
SafeSearchPolicy.MODERATE => "1",
|
||||
@@ -28,6 +28,6 @@ public static class SafeSearchPolicyExtensions
|
||||
/// 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;
|
||||
public bool TavilyValue => policy is not SafeSearchPolicy.OFF;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -129,7 +129,7 @@ public sealed class ReadWebPageTool(WebPageRetrievalService webPageRetrievalServ
|
||||
MAX_CONTENT_CHARACTERS_SETTING => TB("(Optional) Global truncation limit for extracted characters returned to the model."),
|
||||
ALLOWED_PRIVATE_HOSTS_SETTING => TB("(Optional) Host allowlist for private or VPN web pages. For security reasons, private or VPN web pages aren't allowed to be read by default. Separate host patterns with commas, such as example.de, *.example.de. Allowed private hosts require a High-confidence provider. For allowed HTTPS internal hosts, AI Studio also tries the operating system's default sign-in automatically when the server responds with integrated authentication."),
|
||||
FREE_ADDRESS_CHOICE_SETTING => TB("(Optional) With free address choice off, the AI reads only web addresses that appear in the chat, such as in your messages, attached documents, or data sources, or that a tool returned. AI Studio refuses every other address. With it on, the AI may also choose addresses itself. Off is the default."),
|
||||
INTERNAL_PAGE_OUTBOUND_DATA_RESTRICTION_SETTING => string.Format(TB("(Optional) Internal pages are web pages on a private or VPN address and the pages of your Confluence wiki, whatever its address. Once a chat read one, or searched your wiki, a web search or a web address chosen by the AI could carry internal content to third parties. This setting decides what the chat may still use afterwards. With '{0}', the default, the chat does not search the web, but it still reads web pages whose addresses stand in the chat. With '{1}', it reads only pages of your Confluence wiki and of the allowed private hosts. A change applies to pages read later; a chat keeps the level it had when it read a page."), OutboundDataRestriction.ONLY_LINKS_FROM_CHAT.GetName(), OutboundDataRestriction.ONLY_CONFIGURED_SERVICES.GetName()),
|
||||
INTERNAL_PAGE_OUTBOUND_DATA_RESTRICTION_SETTING => string.Format(TB("(Optional) Internal pages are web pages on a private or VPN address and the pages of your Confluence wiki, whatever its address. Once a chat read one, or searched your wiki, a web search or a web address chosen by the AI could carry internal content to third parties. This setting decides what the chat may still use afterwards. With '{0}', the default, the chat does not search the web, but it still reads web pages whose addresses stand in the chat. With '{1}', it reads only pages of your Confluence wiki and of the allowed private hosts. A change applies to pages read later; a chat keeps the level it had when it read a page."), OutboundDataRestriction.ONLY_LINKS_FROM_CHAT.Name, OutboundDataRestriction.ONLY_CONFIGURED_SERVICES.Name),
|
||||
_ => TB(fieldDefinition.Description),
|
||||
};
|
||||
|
||||
@@ -266,7 +266,7 @@ public sealed class ReadWebPageTool(WebPageRetrievalService webPageRetrievalServ
|
||||
/// turn into ON without anybody having written it, see EnumNames. The configuration check
|
||||
/// reports such a value anyway and keeps the tool out of use until somebody corrects it.
|
||||
/// </remarks>
|
||||
internal static FreeAddressChoice ReadFreeAddressChoice(string? configuredValue) => EnumNames.TryParse<FreeAddressChoice>(configuredValue, out var freeAddressChoice) ? freeAddressChoice : DEFAULT_FREE_ADDRESS_CHOICE;
|
||||
internal static FreeAddressChoice ReadFreeAddressChoice(string? configuredValue) => FreeAddressChoice.TryParseName(configuredValue, out var freeAddressChoice) ? freeAddressChoice : DEFAULT_FREE_ADDRESS_CHOICE;
|
||||
|
||||
/// <summary>
|
||||
/// Words the rules the model follows when it reads web pages.
|
||||
@@ -517,7 +517,7 @@ public sealed class ReadWebPageTool(WebPageRetrievalService webPageRetrievalServ
|
||||
if (string.IsNullOrWhiteSpace(configuredValue))
|
||||
return DEFAULT_INTERNAL_PAGE_OUTBOUND_DATA_RESTRICTION;
|
||||
|
||||
return EnumNames.TryParse<OutboundDataRestriction>(configuredValue, out var restriction) ? restriction : OutboundDataRestriction.ONLY_CONFIGURED_SERVICES;
|
||||
return OutboundDataRestriction.TryParseName(configuredValue, out var restriction) ? restriction : OutboundDataRestriction.ONLY_CONFIGURED_SERVICES;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public sealed class SearXNGSearchBackend : IWebSearchBackend
|
||||
|
||||
// No configured policy sends nothing at all, which leaves the decision to the
|
||||
// instance's own configuration:
|
||||
var safeSearch = query.SafeSearch?.ToSearXNGValue();
|
||||
var safeSearch = query.SafeSearch?.SearXNGValue;
|
||||
var response = await this.searchClient.SearchAsync(new SearXNGSearchRequest(searchUri, query.Query, query.Language, query.TimeRange, query.Page, safeSearch, query.Limit, query.TimeoutSeconds), token);
|
||||
|
||||
//
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ public sealed class TavilySearchBackend : IWebSearchBackend
|
||||
// would rather have more hits than one language can choose any language instead.
|
||||
//
|
||||
FilterByLanguage = language is null ? null : true,
|
||||
SafeSearch = query.SafeSearch?.ToTavilyValue(),
|
||||
SafeSearch = query.SafeSearch?.TavilyValue,
|
||||
};
|
||||
|
||||
var response = await this.searchClient.SearchAsync(apiKey.Trim(), searchRequest, query.TimeoutSeconds, token);
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public static class WebSearchBackendExtensions
|
||||
/// 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
|
||||
public string Name => backend switch
|
||||
{
|
||||
WebSearchBackend.SEARXNG => "SearXNG",
|
||||
WebSearchBackend.STAAN => "Staan",
|
||||
|
||||
+5
-5
@@ -80,7 +80,7 @@ internal sealed class WebSearchDispatcher(IEnumerable<IWebSearchBackend> backend
|
||||
if (usesChosenBackend && chosenBackend is null && configuredBackends.Count > 1)
|
||||
{
|
||||
if (primaryBackend is not null)
|
||||
notes.Add($"The chosen search service {primaryBackend.Value.ToName()} is not configured, so the configured services were asked one after another instead.");
|
||||
notes.Add($"The chosen search service {primaryBackend.Value.Name} is not configured, so the configured services were asked one after another instead.");
|
||||
else if (strategy is WebSearchBackendStrategy.SPECIFIC)
|
||||
notes.Add("No search service is chosen, so the configured services were asked one after another instead.");
|
||||
}
|
||||
@@ -118,7 +118,7 @@ internal sealed class WebSearchDispatcher(IEnumerable<IWebSearchBackend> backend
|
||||
throw new InvalidOperationException(TB("None of the search services this search would use can filter explicit results, which the configured safe search policy requires. Please configure a search service that can filter, or turn the policy off."));
|
||||
|
||||
foreach (var backend in backendsToAsk.Where(backend => !backend.Capabilities.SupportsSafeSearch))
|
||||
notes.Add($"{backend.Backend.ToName()} was not asked, because it cannot filter explicit results and the configured safe search policy requires that.");
|
||||
notes.Add($"{backend.Backend.Name} was not asked, because it cannot filter explicit results and the configured safe search policy requires that.");
|
||||
|
||||
return remainingBackends;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ internal sealed class WebSearchDispatcher(IEnumerable<IWebSearchBackend> backend
|
||||
throw new ArgumentException($"Argument 'page' must be less than or equal to {backendsToAsk.Max(backend => backend.Capabilities.MaxPage)}.");
|
||||
|
||||
foreach (var backend in backendsToAsk.Where(backend => query.Page > backend.Capabilities.MaxPage))
|
||||
notes.Add($"{backend.Backend.ToName()} was not asked, because it does not serve result page {query.Page}.");
|
||||
notes.Add($"{backend.Backend.Name} was not asked, because it does not serve result page {query.Page}.");
|
||||
|
||||
return remainingBackends;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ internal sealed class WebSearchDispatcher(IEnumerable<IWebSearchBackend> backend
|
||||
var attributesNotes = outcomes.Count > 1;
|
||||
foreach (var outcome in outcomes)
|
||||
{
|
||||
var backendName = outcome.Backend.Backend.ToName();
|
||||
var backendName = outcome.Backend.Backend.Name;
|
||||
var result = outcome.Result;
|
||||
if (result is null)
|
||||
{
|
||||
@@ -236,7 +236,7 @@ internal sealed class WebSearchDispatcher(IEnumerable<IWebSearchBackend> backend
|
||||
/// </remarks>
|
||||
private static void AppendUnsupportedFilterNotes(List<string> notes, IWebSearchBackend backend, WebSearchQuery query)
|
||||
{
|
||||
var backendName = backend.Backend.ToName();
|
||||
var backendName = backend.Backend.Name;
|
||||
var capabilities = backend.Capabilities;
|
||||
if (!capabilities.SupportsTimeRange && !string.IsNullOrWhiteSpace(query.TimeRange))
|
||||
notes.Add($"{backendName} cannot restrict a search to a period of time, so its hits are not limited to the requested time range '{query.TimeRange}'.");
|
||||
|
||||
+9
-9
@@ -286,7 +286,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
|
||||
var unfilteredBackends = this.dispatcher.GetConfiguredBackends(settingsValues)
|
||||
.Where(backend => !backend.Capabilities.SupportsSafeSearch)
|
||||
.Select(backend => backend.Backend.ToName())
|
||||
.Select(backend => backend.Backend.Name)
|
||||
.ToList();
|
||||
|
||||
if (unfilteredBackends.Count is 0)
|
||||
@@ -362,7 +362,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
return Task.FromResult<ToolConfigurationState?>(new ToolConfigurationState
|
||||
{
|
||||
IsConfigured = false,
|
||||
Message = string.Format(TB("The preferred search service {0} is not configured. Please configure it, or choose one of the services you did configure."), primaryBackend.Value.ToName()),
|
||||
Message = string.Format(TB("The preferred search service {0} is not configured. Please configure it, or choose one of the services you did configure."), primaryBackend.Value.Name),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
return Task.FromResult<ToolConfigurationState?>(new ToolConfigurationState
|
||||
{
|
||||
IsConfigured = false,
|
||||
Message = string.Format(TB("The preferred search service {0} cannot filter explicit results, but a safe search policy is configured and it is the only service that would be used. Please choose another service, let the services be used one after another, or set the safe search policy to off."), chosenBackend.Value.ToName()),
|
||||
Message = string.Format(TB("The preferred search service {0} cannot filter explicit results, but a safe search policy is configured and it is the only service that would be used. Please choose another service, let the services be used one after another, or set the safe search policy to off."), chosenBackend.Value.Name),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -612,7 +612,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
// what tells apart a thin answer from one search service having nothing to say and
|
||||
// a thin answer from the others never having been asked.
|
||||
//
|
||||
["backends"] = BuildJsonArray(searchResponse.Backends.Select(backend => backend.ToName())),
|
||||
["backends"] = BuildJsonArray(searchResponse.Backends.Select(backend => backend.Name)),
|
||||
["candidate_count"] = searchResponse.CandidateCount,
|
||||
["result_count"] = retrievalResult.Results.Count,
|
||||
|
||||
@@ -654,7 +654,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
"Completed web search. ToolCallId={ToolCallId}, Strategy={Strategy}, Backends={Backends}, CandidateCount={CandidateCount}, ResultCount={ResultCount}, RetrievedPageCount={RetrievedPageCount}, BlockedPageCount={BlockedPageCount}, PageTimeoutCount={PageTimeoutCount}, FailedPageCount={FailedPageCount}, EmptyContentCount={EmptyContentCount}, RetrievalTimedOut={RetrievalTimedOut}, ReturnedContentCharacters={ReturnedContentCharacters}, TruncatedResultCount={TruncatedResultCount}, Notes={Notes}",
|
||||
context.ToolCallId,
|
||||
backendStrategy,
|
||||
string.Join(", ", searchResponse.Backends.Select(backend => backend.ToName())),
|
||||
string.Join(", ", searchResponse.Backends.Select(backend => backend.Name)),
|
||||
searchResponse.CandidateCount,
|
||||
retrievalResult.Results.Count,
|
||||
retrievedPageCount,
|
||||
@@ -694,7 +694,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
private static WebSearchBackendStrategy ReadBackendStrategy(IReadOnlyDictionary<string, string> settingsValues)
|
||||
{
|
||||
var configuredStrategy = settingsValues.GetValueOrDefault(BACKEND_STRATEGY_SETTING);
|
||||
return EnumNames.TryParse<WebSearchBackendStrategy>(configuredStrategy, out var strategy) ? strategy : DEFAULT_BACKEND_STRATEGY;
|
||||
return WebSearchBackendStrategy.TryParseName(configuredStrategy, out var strategy) ? strategy : DEFAULT_BACKEND_STRATEGY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -708,7 +708,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
private static WebSearchBackend? ReadPrimaryBackend(IReadOnlyDictionary<string, string> settingsValues)
|
||||
{
|
||||
var configuredBackend = settingsValues.GetValueOrDefault(PRIMARY_BACKEND_SETTING);
|
||||
return EnumNames.TryParse<WebSearchBackend>(configuredBackend, out var backend) ? backend : null;
|
||||
return WebSearchBackend.TryParseName(configuredBackend, out var backend) ? backend : null;
|
||||
}
|
||||
|
||||
private static JsonObject BuildResultJson(WebSearchPageResult result, WebPageModelContent sanitizedContent)
|
||||
@@ -719,7 +719,7 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
|
||||
// Two services having found the same page says something about the page that
|
||||
// neither of them says alone, so it is reported per hit and not only per search:
|
||||
["backends"] = BuildJsonArray(result.Candidate.Backends.Select(backend => backend.ToName())),
|
||||
["backends"] = BuildJsonArray(result.Candidate.Backends.Select(backend => backend.Name)),
|
||||
};
|
||||
|
||||
//
|
||||
@@ -875,6 +875,6 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
|
||||
private static SafeSearchPolicy? ReadSafeSearchPolicy(IReadOnlyDictionary<string, string> settingsValues)
|
||||
{
|
||||
var configuredPolicy = settingsValues.GetValueOrDefault(DEFAULT_SAFE_SEARCH_SETTING);
|
||||
return EnumNames.TryParse<SafeSearchPolicy>(configuredPolicy, out var policy) ? policy : null;
|
||||
return SafeSearchPolicy.TryParseName(configuredPolicy, out var policy) ? policy : null;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public static class ToolSettingsOptionSources
|
||||
// translation. Adding a search service therefore adds it to this list, and to the
|
||||
// dropdown offering it, without a line of code here:
|
||||
//
|
||||
WEB_SEARCH_BACKENDS => Enum.GetValues<WebSearchBackend>().Select(backend => new ToolSettingsOption(backend.ToString(), backend.ToName())).ToList(),
|
||||
WEB_SEARCH_BACKENDS => Enum.GetValues<WebSearchBackend>().Select(backend => new ToolSettingsOption(backend.ToString(), backend.Name)).ToList(),
|
||||
WEB_SEARCH_BACKEND_STRATEGY =>
|
||||
[
|
||||
new(nameof(WebSearchBackendStrategy.FAILOVER), TB("One after another, until one answers")),
|
||||
@@ -114,7 +114,7 @@ public static class ToolSettingsOptionSources
|
||||
new(nameof(FreeAddressChoice.ON), TB("On: the AI may also choose web addresses itself")),
|
||||
],
|
||||
|
||||
OUTBOUND_DATA_RESTRICTION => Enum.GetValues<OutboundDataRestriction>().Select(restriction => new ToolSettingsOption(restriction.ToString(), restriction.GetName())).ToList(),
|
||||
OUTBOUND_DATA_RESTRICTION => Enum.GetValues<OutboundDataRestriction>().Select(restriction => new ToolSettingsOption(restriction.ToString(), restriction.Name)).ToList(),
|
||||
|
||||
_ => [],
|
||||
};
|
||||
@@ -136,9 +136,9 @@ public static class ToolSettingsOptionSources
|
||||
// user may keep a text as it is or type a language of their own. A search engine needs
|
||||
// a concrete tag, and ANY_LANGUAGE above already covers "no preference".
|
||||
//
|
||||
var tag = language.ToIETFTag();
|
||||
var tag = language.IETFTag;
|
||||
if (!string.IsNullOrWhiteSpace(tag))
|
||||
options.Add(new(tag, language.Name()));
|
||||
options.Add(new(tag, language.Name));
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
Reference in new issue
Block a user