mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-10 17:13:48 +00:00
Fixed answers breaking off after an invalid tool call (#1036)
This commit is contained in:
1 parent
b895cf674b
commit
88f71d2405
6 files changed
+202
-32
No files matched your search
@@ -48,6 +48,20 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService, ILogge
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether a function name consists of 1 to 64 ASCII letters, digits, underscores, or hyphens.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The rule OpenAI states for function names. Our own definitions have to meet it to be offered
|
||||
/// at all, and every name a model returned has to meet it to be sent back in the conversation:
|
||||
/// vLLM checks the calls of the history with exactly this rule when it serves a Mistral model,
|
||||
/// and it rejects the whole request over a single name which breaks it.
|
||||
/// </remarks>
|
||||
public static bool IsValidFunctionName(string? functionName) =>
|
||||
!string.IsNullOrWhiteSpace(functionName) &&
|
||||
functionName.Length <= 64 &&
|
||||
functionName.All(character => char.IsAsciiLetterOrDigit(character) || character is '_' or '-');
|
||||
|
||||
public async Task<ToolCallOutcome> ExecuteAsync(
|
||||
string toolCallId,
|
||||
string toolName,
|
||||
|
||||
@@ -193,7 +193,7 @@ public sealed class ToolRegistry
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsValidFunctionName(definition.Function.Name))
|
||||
if (!ToolExecutor.IsValidFunctionName(definition.Function.Name))
|
||||
{
|
||||
issue = "the function name must contain 1-64 ASCII letters, digits, underscores, or hyphens";
|
||||
return false;
|
||||
@@ -279,11 +279,6 @@ public sealed class ToolRegistry
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsValidFunctionName(string? functionName) =>
|
||||
!string.IsNullOrWhiteSpace(functionName) &&
|
||||
functionName.Length <= 64 &&
|
||||
functionName.All(character => char.IsAsciiLetterOrDigit(character) || character is '_' or '-');
|
||||
|
||||
public IReadOnlyList<ToolDefinition> GetDefinitionsForComponent(Components component)
|
||||
{
|
||||
return this.definitionsById.Values
|
||||
|
||||
Reference in new issue
Block a user