Skip to content

Commit

Permalink
minor tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Feb 21, 2024
1 parent d0c2888 commit f806352
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions OpenAI-DotNet/Assistants/AssistantExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,8 @@ public static async Task<bool> DeleteFileAsync(this AssistantResponse assistant,
/// <returns>Tool output result as <see cref="string"/></returns>
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();
}
Expand All @@ -207,13 +202,8 @@ public static string InvokeToolCall(this AssistantResponse assistant, ToolCall t
/// <returns>Tool output result as <see cref="string"/></returns>
public static async Task<string> 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);
}
Expand Down

0 comments on commit f806352

Please sign in to comment.