Class KernelFunctionFromMethod<T>
- java.lang.Object
-
- com.microsoft.semantickernel.semanticfunctions.KernelFunction<T>
-
- com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromMethod<T>
-
- Type Parameters:
T- the return type of the function
public class KernelFunctionFromMethod<T> extends KernelFunction<T>
AKernelFunctionthat is created from a method. This class is used to create aKernelFunctionfrom a method that is annotated withDefineKernelFunctionandKernelFunctionParameter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKernelFunctionFromMethod.Builder<T>A builder forKernelFunction.static interfaceKernelFunctionFromMethod.ImplementationFunc<T>Concrete implementation of the abstract method in KernelFunction.-
Nested classes/interfaces inherited from class com.microsoft.semantickernel.semanticfunctions.KernelFunction
KernelFunction.FromPromptBuilder<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> KernelFunctionFromMethod.Builder<T>builder()A builder forKernelFunction.static <T> KernelFunction<T>create(Method method, Object target, String pluginName, String functionName, String description, List<InputVariable> parameters, OutputVariable<?> returnParameter)Creates a new instance ofKernelFunctionFromMethodfrom a method.static List<String>getEnumOptions(Class<?> type)reactor.core.publisher.Mono<FunctionResult<T>>invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)Concrete implementation of the abstract method in KernelFunction.-
Methods inherited from class com.microsoft.semantickernel.semanticfunctions.KernelFunction
createFromMethod, createFromPrompt, createFromPrompt, getDescription, getExecutionSettings, getMetadata, getName, getPluginName, invoke, invoke, invokeAsync, toEmbeddingString, toManualString
-
-
-
-
Method Detail
-
create
public static <T> KernelFunction<T> create(Method method, Object target, @Nullable String pluginName, @Nullable String functionName, @Nullable String description, @Nullable List<InputVariable> parameters, @Nullable OutputVariable<?> returnParameter)
Creates a new instance ofKernelFunctionFromMethodfrom a method.- Type Parameters:
T- the return type of the function- Parameters:
method- the method to create the function fromtarget- the instance of the class that the method is a member ofpluginName- the name of the plugin which the function belongs tofunctionName- the name of the functiondescription- the description of the functionparameters- the parameters of the functionreturnParameter- the return parameter of the function- Returns:
- a new instance of
KernelFunctionFromMethod
-
builder
public static <T> KernelFunctionFromMethod.Builder<T> builder()
A builder forKernelFunction.- Type Parameters:
T- the return type of the function- Returns:
- a new instance of
KernelFunctionFromMethod.Builder
-
invokeAsync
public reactor.core.publisher.Mono<FunctionResult<T>> invokeAsync(Kernel kernel, @Nullable KernelFunctionArguments arguments, @Nullable ContextVariableType<T> variableType, @Nullable InvocationContext invocationContext)
Concrete implementation of the abstract method in KernelFunction. Invokes this KernelFunction.If the
variableTypeparameter is provided, theContextVariableTypeis used to convert the result of the function to the appropriateFunctionResult. ThevariableTypeis not required for converting well-known types such asStringandIntegerwhich have pre-definedContextVariableTypes.The
InvocationContextallows for customization of the behavior of function, including the ability to pass inKernelHooksPromptExecutionSettings, andToolCallBehavior.The difference between calling the
KernelFunction.invokeAsyncmethod directly and calling theKernel.invokeAsyncmethod is that the latter adds the global KernelHooks (if any) to theInvocationContext. CallingKernelFunction.invokeAsyncdirectly does not add the global hooks.- Specified by:
invokeAsyncin classKernelFunction<T>- Parameters:
kernel- The Kernel containing services, plugins, and other state for use throughout the operation.arguments- The arguments to pass to the function's invocationvariableType- The type of theContextVariablereturned in theFunctionResultinvocationContext- The arguments to pass to the function's invocation- Returns:
- The result of the function's execution.
- See Also:
FunctionResult.getResultVariable()
-
-