Class GenericFunctionTool
- Namespace
- GenerativeAI.Tools
- Assembly
- GenerativeAI.Tools.dll
GenericFunctionTool provides a generic implementation of the IFunctionTool interface, allowing seamless interaction with a collection of tools and their corresponding functions. It utilizes the code generation capabilities available in CSharpToJsonSchema for transforming tool definitions into executable formats and managing function invocations.
public class GenericFunctionTool : GoogleFunctionTool, IFunctionTool
- Inheritance
-
GenericFunctionTool
- Implements
- Inherited Members
- Extension Methods
Constructors
GenericFunctionTool(IEnumerable<Tool>, IReadOnlyDictionary<string, Func<string, CancellationToken, Task<string>>>)
Represents a generic functional tool that enables interaction with a set of tools and their associated functions, facilitating the conversion of provided tools into a compatible format for execution and integration.
public GenericFunctionTool(IEnumerable<Tool> tools, IReadOnlyDictionary<string, Func<string, CancellationToken, Task<string>>> calls)
Parameters
toolsIEnumerable<Tool>callsIReadOnlyDictionary<string, Func<string, CancellationToken, Task<string>>>
Properties
Calls
Gets the dictionary of function calls mapped by function name.
public IReadOnlyDictionary<string, Func<string, CancellationToken, Task<string>>> Calls { get; }
Property Value
Tools
Gets the list of tools available for this generic function tool.
public IReadOnlyList<Tool> Tools { get; }
Property Value
- IReadOnlyList<Tool>
Methods
AsTool()
Converts the current instance to a Tool object.
public override Tool AsTool()
Returns
CallAsync(FunctionCall, CancellationToken)
Executes the specified FunctionCall asynchronously and retrieves the resulting FunctionResponse containing any output from the function execution.
public override Task<FunctionResponse?> CallAsync(FunctionCall functionCall, CancellationToken cancellationToken = default)
Parameters
functionCallFunctionCallThe FunctionCall instance containing the name and arguments required for the function execution.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<FunctionResponse>
A task representing the asynchronous operation, which, upon completion, provides a FunctionResponse with the execution results.
IsContainFunction(string)
Determines whether the specified function exists within the current tool's context.
public override bool IsContainFunction(string name)
Parameters
namestringThe name of the function to check for existence.
Returns
- bool
A boolean value indicating whether the function is present.