Share via


KernelFunctionFromMethod<T> Class

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 KernelFunction<T> 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 ImplementationFunc<T> 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<FunctionResult<T>> invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)

Concrete implementation of the abstract method in KernelFunction.

Methods inherited from KernelFunction

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

builder

public static KernelFunctionFromMethod.Builder builder()

A builder for KernelFunction<T>.

Returns:

create

public static KernelFunction create(Method method, Object target, String pluginName, String functionName, String description, List parameters, OutputVariable returnParameter)

Creates a new instance of KernelFunctionFromMethod<T> from a method.

Parameters:

method - the method to create the function from
target - the instance of the class that the method is a member of
pluginName - the name of the plugin which the function belongs to
functionName - the name of the function
description - the description of the function
parameters - the parameters of the function
returnParameter - the return parameter of the function

Returns:

a new instance of KernelFunctionFromMethod<T>

getFunction

public static KernelFunctionFromMethod.ImplementationFunc getFunction(Method method, Object instance)

Gets the function from the method.

Parameters:

method - the method to invoke
instance - the instance to invoke the method on

Returns:

the function representing the method

getEnumOptions

public static List getEnumOptions(Class type)

Gets the constants from an enum type.

Parameters:

type - the type to get the enum constants from

Returns:

a list of the enum constants or null if the type is not an enum

invokeAsync

public Mono> invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType variableType, InvocationContext invocationContext)

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 ContextVariableTypes.

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:

kernel
arguments
variableType
invocationContext

Applies to