mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-25 04:55:19 +00:00
Added a check for characters which an API key cannot contain (#1227)
This commit is contained in:
1 parent
c72a1948b3
commit
e5a7f5423f
40 files changed
+1179
-71
No files matched your search
+10
-2
@@ -1,4 +1,5 @@
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.Validation;
|
||||
|
||||
namespace AIStudio.Tools.ToolCallingSystem.ToolCallingImplementations.WebSearch.Staan;
|
||||
|
||||
@@ -65,7 +66,7 @@ public sealed class StaanSearchBackend : IWebSearchBackend
|
||||
|
||||
public void DeclareSettings(ToolSettingsSchemaBuilder builder) => builder
|
||||
.InGroup(SETTINGS_GROUP)
|
||||
.OptionalSecret(API_KEY_SETTING)
|
||||
.OptionalAPIKey(API_KEY_SETTING)
|
||||
.OptionalEnum(MARKET_SETTING, SUPPORTED_MARKETS)
|
||||
.InGroup(string.Empty);
|
||||
|
||||
@@ -125,6 +126,13 @@ public sealed class StaanSearchBackend : IWebSearchBackend
|
||||
if (string.IsNullOrWhiteSpace(apiKey))
|
||||
throw new InvalidOperationException(TB("A Staan API key is required."));
|
||||
|
||||
//
|
||||
// A key stored before AI Studio checked keys, or one the organization provides, may hold a
|
||||
// character the header cannot carry. The dispatcher asks the other services all the same:
|
||||
//
|
||||
if (!APIKeyValidation.TryPrepareForHeader(apiKey, out var headerAPIKey))
|
||||
throw new InvalidOperationException(APIKeyValidation.GetUnusableKeyMessage("Staan"));
|
||||
|
||||
//
|
||||
// Staan refuses a longer query outright. Shortening it here would search for something
|
||||
// other than what was asked, so the model is told and can search again instead:
|
||||
@@ -141,7 +149,7 @@ public sealed class StaanSearchBackend : IWebSearchBackend
|
||||
var market = ResolveMarket(query.Language, settingsValues, notes);
|
||||
|
||||
var searchRequest = new StaanSearchRequest { Query = query.Query, Market = market, Offset = ReadOffset(query.Page) };
|
||||
var response = await this.searchClient.SearchAsync(apiKey.Trim(), searchRequest, query.TimeoutSeconds, token);
|
||||
var response = await this.searchClient.SearchAsync(headerAPIKey, searchRequest, query.TimeoutSeconds, token);
|
||||
|
||||
//
|
||||
// Staan corrects an obvious mistake in a query and says so. Which query actually ran is
|
||||
|
||||
Reference in new issue
Block a user