diff --git a/OpenAI-DotNet/Assistants/AssistantExtensions.cs b/OpenAI-DotNet/Assistants/AssistantExtensions.cs index 5db2a6cf..5e3789a7 100644 --- a/OpenAI-DotNet/Assistants/AssistantExtensions.cs +++ b/OpenAI-DotNet/Assistants/AssistantExtensions.cs @@ -187,13 +187,8 @@ public static async Task DeleteFileAsync(this AssistantResponse assistant, /// Tool output result as public static string InvokeToolCall(this AssistantResponse assistant, ToolCall toolCall) { - var tool = assistant.Tools.FirstOrDefault(tool => toolCall.Type == "function" && tool.Function.Name == toolCall.FunctionCall.Name); - - if (tool == null) - { + var tool = assistant.Tools.FirstOrDefault(tool => toolCall.Type == "function" && tool.Function.Name == toolCall.FunctionCall.Name) ?? throw new InvalidOperationException($"Failed to find a valid tool for [{toolCall.Id}] {toolCall.Type}"); - } - tool.Function.Arguments = toolCall.FunctionCall.Arguments; return tool.InvokeFunction(); } @@ -207,13 +202,8 @@ public static string InvokeToolCall(this AssistantResponse assistant, ToolCall t /// Tool output result as public static async Task InvokeToolCallAsync(this AssistantResponse assistant, ToolCall toolCall, CancellationToken cancellationToken = default) { - var tool = assistant.Tools.FirstOrDefault(tool => toolCall.Type == "function" && tool.Function.Name == toolCall.FunctionCall.Name); - - if (tool == null) - { + var tool = assistant.Tools.FirstOrDefault(tool => toolCall.Type == "function" && tool.Function.Name == toolCall.FunctionCall.Name) ?? throw new InvalidOperationException($"Failed to find a valid tool for [{toolCall.Id}] {toolCall.Type}"); - } - tool.Function.Arguments = toolCall.FunctionCall.Arguments; return await tool.InvokeFunctionAsync(cancellationToken).ConfigureAwait(false); }