From 4dd9d168f5c75409c8a12d8c4d4d63875f5e91ee Mon Sep 17 00:00:00 2001
From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com>
Date: Mon, 1 Jul 2024 12:33:48 -0500
Subject: [PATCH] feat: add support for delegate with two parameters
---
src/AnthropicClient/Models/Tool.cs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/AnthropicClient/Models/Tool.cs b/src/AnthropicClient/Models/Tool.cs
index 9d667ce..bb70153 100644
--- a/src/AnthropicClient/Models/Tool.cs
+++ b/src/AnthropicClient/Models/Tool.cs
@@ -147,6 +147,26 @@ public class Tool
return new Tool(name, description, new AnthropicFunction(func.Method, func.Target));
}
+ ///
+ /// Creates a tool from a function.
+ ///
+ /// The type of the first parameter for the delegate.
+ /// The type of the second parameter for the delegate.
+ /// The type of the result for the delegate.
+ /// The name of the tool.
+ /// The description of the tool.
+ /// The function.
+ /// Thrown when is null.
+ /// The created tool as instance of .
+ /// The name of the tool will be sanitized to conform to the Anthropic tool naming rules.
+ public static Tool CreateFromFunction(string name, string description, Func func)
+ {
+ ArgumentValidator.ThrowIfNull(func, nameof(func));
+
+ return new Tool(name, description, new AnthropicFunction(func.Method, func.Target));
+ }
+
+
private static string SanitizeName(string name)
{
var sanitizedName = name.Trim();