Share via


KernelFunctionFromPrompt<T> Class

Type Parameters

T

the type of the return value of the function

public class KernelFunctionFromPrompt
extends KernelFunction<T>

A KernelFunction<T> implementation that is created from a prompt template.

Constructor Summary

Modifier Constructor Description
protected KernelFunctionFromPrompt(PromptTemplate template, PromptTemplateConfig promptConfig, Map<String,PromptExecutionSettings> executionSettings)

Creates a new instance of KernelFunctionFromPrompt<T>.

Method Summary

Modifier and Type Method and Description
static Builder<T> builder()

Creates a new instance of KernelFunctionFromPrompt.Builder<T>.

static Builder<T> builder(Class<T> returnType)

Creates a new instance of KernelFunctionFromPrompt.Builder<T>.

reactor.core.publisher.Mono<FunctionResult<T>> invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)

Invokes this 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

Constructor Details

KernelFunctionFromPrompt

protected KernelFunctionFromPrompt(PromptTemplate template, PromptTemplateConfig promptConfig, Map executionSettings)

Creates a new instance of KernelFunctionFromPrompt<T>.

Parameters:

template - the prompt template to use for the function
promptConfig - the configuration for the prompt
executionSettings - the execution settings to use when invoking the function

Method Details

builder

public static KernelFunctionFromPrompt.Builder builder()

Creates a new instance of KernelFunctionFromPrompt.Builder<T>.

Returns:

builder

public static KernelFunctionFromPrompt.Builder builder(Class returnType)

Creates a new instance of KernelFunctionFromPrompt.Builder<T>.

Parameters:

returnType - The type of the return value of the function

Returns:

invokeAsync

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

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:

KernelFunctionFromPrompt<T>.invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)

Parameters:

kernel
arguments
variableType
invocationContext

Applies to