Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Bug Fix #63

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Anthropic.SDK/Anthropic.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<PackageTags>Claude, AI, ML, API, Anthropic</PackageTags>
<Title>Claude API</Title>
<PackageReleaseNotes>
Updates Microsoft.Extensions.AI.Abstractions Use
Minor Bug Fix
</PackageReleaseNotes>
<PackageId>Anthropic.SDK</PackageId>
<Version>4.4.1</Version>
<AssemblyVersion>4.4.1.0</AssemblyVersion>
<FileVersion>4.4.1.0</FileVersion>
<Version>4.4.2</Version>
<AssemblyVersion>4.4.2.0</AssemblyVersion>
<FileVersion>4.4.2.0</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
Expand Down
20 changes: 19 additions & 1 deletion Anthropic.SDK/Common/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ private static bool TryGetTool(string name, object instance, out Tool tool)
return false;
}

private static IEnumerable<Type> GetAssemblyTypes(Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
// Return the types that could be loaded
return ex.Types.Where(t => t != null);
}
catch
{
// Return an empty sequence if any other exception occurs
return Enumerable.Empty<Type>();
}
}

/// <summary>
/// Gets a list of all available tools.
/// </summary>
Expand All @@ -191,7 +209,7 @@ public static IReadOnlyList<Tool> GetAllAvailableTools(bool includeDefaults = tr
var tools = new List<Tool>();
tools.AddRange(
from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from type in GetAssemblyTypes(assembly)
from method in type.GetMethods()
where method.IsStatic
let functionAttribute = method.GetCustomAttribute<FunctionAttribute>()
Expand Down
Loading