Skip to content

Commit

Permalink
tweaks and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Feb 21, 2024
1 parent 4b7321e commit d0c2888
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
22 changes: 5 additions & 17 deletions OpenAI-DotNet/Common/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal void CopyFrom(Function other)
}
}

#region Function Inoking Utilities
#region Function Invoking Utilities

private static readonly Dictionary<string, MethodInfo> functionCache = new();

Expand Down Expand Up @@ -198,24 +198,12 @@ public async Task<string> InvokeAsync(CancellationToken cancellationToken = defa
throw new InvalidOperationException($"Failed to lookup and invoke function \"{Name}\"");
}

var type = Type.GetType(Name[..Name.LastIndexOf('_')].Replace('_', '.'));

if (type == null)
{
throw new InvalidOperationException($"Failed to find a valid type for {Name}");
}

method = type.GetMethod(Name[(Name.LastIndexOf('_') + 1)..].Replace('_', '.'));

if (method == null)
{
throw new InvalidOperationException($"Failed to find a valid method for {Name}");
}

var type = Type.GetType(Name[..Name.LastIndexOf('_')].Replace('_', '.')) ?? throw new InvalidOperationException($"Failed to find a valid type for {Name}");
method = type.GetMethod(Name[(Name.LastIndexOf('_') + 1)..].Replace('_', '.')) ?? throw new InvalidOperationException($"Failed to find a valid method for {Name}");
functionCache[Name] = method;
}

var requestedArgs = JsonSerializer.Deserialize<Dictionary<string, object>>(Arguments.ToString());
var requestedArgs = JsonSerializer.Deserialize<Dictionary<string, object>>(Arguments.ToString(), OpenAIClient.JsonSerializationOptions);
var methodParams = method.GetParameters();
var invokeArgs = new object[methodParams.Length];

Expand Down Expand Up @@ -256,6 +244,6 @@ public async Task<string> InvokeAsync(CancellationToken cancellationToken = defa
return (method, invokeArgs);
}

#endregion Function Inoking Utilities
#endregion Function Invoking Utilities
}
}
7 changes: 6 additions & 1 deletion OpenAI-DotNet/Common/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ internal void CopyFrom(Tool other)

public static IReadOnlyList<Tool> GetAllAvailableTools(bool includeDefaults = true)
{
if (toolCache != null) { return toolCache; }
if (toolCache != null)
{
return !includeDefaults
? toolCache.Where(tool => tool.Type == "function").ToList()
: toolCache;
}

var tools = new List<Tool>();

Expand Down

0 comments on commit d0c2888

Please sign in to comment.