KernelFunction<T> Class
- java.
lang. Object - com.
microsoft. semantickernel. semanticfunctions. KernelFunction<T>
- com.
Type Parameters
- T
The type of the result of the function
public abstract class KernelFunction
Semantic Kernel callable function interface. The Semantic Kernel creates KernelFunction
s from prompts, templates, or plugin methods.
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
protected | KernelFunction(KernelFunctionMetadata<?> metadata, Map<String,PromptExecutionSettings> executionSettings) |
Create a new instance of Kernel |
Method Summary
Modifier and Type | Method and Description |
---|---|
static Builder<T> |
createFromMethod(Method method, Object target)
Creates a KernelFunction<T> instance for a method, specified via a Method instance |
static
From |
createFromPrompt(PromptTemplateConfig promptTemplateConfiguration)
Builder for creating a KernelFunction<T> instance for a given PromptTemplateConfig. |
static
From |
createFromPrompt(String prompt)
Creates a KernelFunction<T> instance based on a given prompt |
java.lang.String |
getDescription()
Get the description of the function. |
java.util.Map<java.lang.String,Prompt |
getExecutionSettings()
Get an unmodifiable map of the execution settings for the function. |
Kernel |
getMetadata()
Get the metadata for the function. |
java.lang.String |
getName()
Get the name of the function. |
java.lang.String |
getPluginName()
Get the plugin name of the function. |
Function |
invoke(Kernel kernel)
Invokes this Kernel |
Function |
invoke(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)
Invokes this Kernel |
Function |
invokeAsync(Kernel kernel)
Invokes this Kernel |
abstract
reactor.core.publisher.Mono<Function |
invokeAsync(Kernel kernel, KernelFunctionArguments arguments, ContextVariableType<T> variableType, InvocationContext invocationContext)
Invokes this Kernel |
java.lang.String |
toEmbeddingString()
Create a string for generating an embedding for a function. |
java.lang.String |
toManualString(boolean includeOutputs)
Create a manual-friendly string for a function. |
Methods inherited from java.lang.Object
Constructor Details
KernelFunction
protected KernelFunction(KernelFunctionMetadata metadata, Map
Create a new instance of KernelFunction.
Parameters:
Method Details
createFromMethod
public static KernelFunctionFromMethod.Builder
Creates a KernelFunction<T> instance for a method, specified via a Method instance
Parameters:
method
if it represents an instance method.
This should be null
if and only if method
is a static method.
Returns:
method
.createFromPrompt
public static KernelFunction.FromPromptBuilder
Builder for creating a KernelFunction<T> instance for a given PromptTemplateConfig.
Parameters:
Returns:
createFromPrompt
public static KernelFunction.FromPromptBuilder
Creates a KernelFunction<T> instance based on a given prompt
Parameters:
Returns:
getDescription
public String getDescription()
Get the description of the function.
Returns:
getExecutionSettings
public Map
Get an unmodifiable map of the execution settings for the function.
Returns:
getMetadata
public KernelFunctionMetadata getMetadata()
Get the metadata for the function.
Returns:
getName
public String getName()
Get the name of the function.
Returns:
getPluginName
public String getPluginName()
Get the plugin name of the function.
Returns:
invoke
public FunctionResult
Invokes this KernelFunction.
Parameters:
Returns:
invoke
public FunctionResult
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.
Parameters:
Returns:
invokeAsync
public FunctionInvocation
Invokes this KernelFunction.
Parameters:
Returns:
invokeAsync
public abstract Mono
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.
Parameters:
Returns:
toEmbeddingString
public String toEmbeddingString()
Create a string for generating an embedding for a function.
Returns:
toManualString
public String toManualString(boolean includeOutputs)
Create a manual-friendly string for a function.
Parameters:
Returns: