KernelFunctionFromMethod<T> Class
- java.
lang. Object - com.
microsoft. semantickernel. semanticfunctions. KernelFunction<T> - com.
microsoft. semantickernel. semanticfunctions. KernelFunctionFromMethod<T>
- com.
- com.
Type Parameters
- T
the return type of the function
public class KernelFunctionFromMethod
extends KernelFunction<T>
A KernelFunction<T> that is created from a method. This class is used to create a KernelFunction<T> from a method that is annotated with DefineKernelFunction and KernelFunctionParameter.
Method Summary
Modifier and Type | Method and Description |
---|---|
static Builder<T> |
builder()
A builder for KernelFunction<T>. |
static
Kernel |
create(Method method, Object target, String pluginName, String functionName, String description, List<InputVariable> parameters, OutputVariable<?> returnParameter)
Creates a new instance of KernelFunctionFromMethod<T> from a method. |
static
Implementation |
getFunction(Method method, Object instance)
Gets the function from the method. |
static java.util.List<java.lang.String> |
getEnumOptions(Class<?> type)
Gets the constants from an enum type. |
reactor.core.publisher.Mono<Function |
invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)
Concrete implementation of the abstract method in Kernel |
Methods inherited from KernelFunction
Methods inherited from java.lang.Object
Method Details
builder
public static KernelFunctionFromMethod.Builder
A builder for KernelFunction<T>.
Returns:
create
public static KernelFunction
Creates a new instance of KernelFunctionFromMethod<T> from a method.
Parameters:
Returns:
getFunction
public static KernelFunctionFromMethod.ImplementationFunc
Gets the function from the method.
Parameters:
Returns:
getEnumOptions
public static List
Gets the constants from an enum type.
Parameters:
Returns:
null
if the type is not an enuminvokeAsync
public Mono
Concrete implementation of the abstract method in KernelFunction. Invokes this KernelFunction.
If the variableType
parameter is provided, the ContextVariableType<T> is used to convert the result of the function to the appropriate FunctionResult<T>. The variableType
is not required for converting well-known types such as String and Integer which have pre-defined ContextVariableType
s.
The InvocationContext allows for customization of the behavior of function, including the ability to pass in KernelHooks PromptExecutionSettings, and ToolCallBehavior.
The difference between calling the KernelFunction.invokeAsync
method directly and calling the Kernel.invokeAsync
method is that the latter adds the global KernelHooks (if any) to the InvocationContext. Calling KernelFunction.invokeAsync
directly does not add the global hooks.
Overrides:
KernelFunctionFromMethod<T>.invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)Parameters: