functions Package
Modules
Classes
FunctionResult |
The result of a function. Create a new model by parsing and validating input data from keyword arguments. Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. self is explicitly positional-only to allow self as a field name. |
KernelArguments |
The arguments sent to the KernelFunction. Initializes a new instance of the KernelArguments class. This is a dict-like class with the additional field for the execution_settings. This class is derived from a dict, hence behaves the same way, just adds the execution_settings as a dict, with service_id and the settings. |
KernelFunction |
Semantic Kernel function. Create a new model by parsing and validating input data from keyword arguments. Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. self is explicitly positional-only to allow self as a field name. |
KernelFunctionFromMethod |
Semantic Kernel Function from a method. Initializes a new instance of the KernelFunctionFromMethod class. |
KernelFunctionFromPrompt |
Semantic Kernel Function from a prompt. Initializes a new instance of the KernelFunctionFromPrompt class. |
KernelFunctionMetadata |
The kernel function metadata. Create a new model by parsing and validating input data from keyword arguments. Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. self is explicitly positional-only to allow self as a field name. |
KernelParameterMetadata |
The kernel parameter metadata. Create a new model by parsing and validating input data from keyword arguments. Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. self is explicitly positional-only to allow self as a field name. |
KernelPlugin |
Represents a Kernel Plugin with functions. This class behaves mostly like a dictionary, with functions as values and their names as keys. When you add a function, through .set or setitem, the function is copied, the metadata is deep-copied and the name of the plugin is set in the metadata and added to the dict of functions. This is done in the same way as a normal dict, so a existing key will be overwritten. Class methods: from_object(plugin_name: str, plugin_instance: Any | dict[str, Any], description: str | None = None): Create a plugin from a existing object, like a custom class with annotated functions. from_directory(plugin_name: str, parent_directory: str, description: str | None = None): Create a plugin from a directory, parsing: .py files, .yaml files and directories with skprompt.txt and config.json files. from_openapi( plugin_name: str, openapi_document_path: str, execution_settings: OpenAPIFunctionExecutionParameters | None = None, description: str | None = None):
Create a KernelPlugin. |
Functions
kernel_function
Decorator for kernel functions.
Can be used directly as @kernel_function or with parameters @kernel_function(name='function', description='I am a function.').
This decorator is used to mark a function as a kernel function. It also provides metadata for the function. The name and description can be left empty, and then the function name and docstring will be used.
The parameters are parsed from the function signature, use typing.Annotated to provide a description for the parameter.
To parse the type, first it checks if the parameter is annotated, and get's the description from there. After that it checks recursively until it reaches the lowest level, and it combines the types into a single comma-separated string, a forwardRef is also supported. All of this is are stored in kernel_function_parameters.
The return type and description are parsed from the function signature, and that is stored in kernel_function_return_type, kernel_function_return_description and kernel_function_return_required.
It also checks if the function is a streaming type (generator or iterable, async or not), and that is stored as a bool in kernel_function_streaming.
kernel_function(func: Callable[[...], object] | None = None, name: str | None = None, description: str | None = None) -> Callable[[...], Any]
Parameters
Name | Description |
---|---|
func
|
The function to decorate, can be None (if used as @kernel_function Default value: None
|
name
|
<xref:<xref:semantic_kernel.functions.str | None>>
The name of the function, if not supplied, the function name will be used. Default value: None
|
description
|
<xref:<xref:semantic_kernel.functions.str | None>>
The description of the function, if not supplied, the function docstring will be used, can be None. Default value: None
|
kernel_function
Decorator for kernel functions.
Can be used directly as @kernel_function or with parameters @kernel_function(name='function', description='I am a function.').
This decorator is used to mark a function as a kernel function. It also provides metadata for the function. The name and description can be left empty, and then the function name and docstring will be used.
The parameters are parsed from the function signature, use typing.Annotated to provide a description for the parameter.
To parse the type, first it checks if the parameter is annotated, and get's the description from there. After that it checks recursively until it reaches the lowest level, and it combines the types into a single comma-separated string, a forwardRef is also supported. All of this is are stored in kernel_function_parameters.
The return type and description are parsed from the function signature, and that is stored in kernel_function_return_type, kernel_function_return_description and kernel_function_return_required.
It also checks if the function is a streaming type (generator or iterable, async or not), and that is stored as a bool in kernel_function_streaming.
kernel_function(func: Callable[[...], object] | None = None, name: str | None = None, description: str | None = None) -> Callable[[...], Any]
Parameters
Name | Description |
---|---|
func
|
The function to decorate, can be None (if used as @kernel_function Default value: None
|
name
|
<xref:<xref:semantic_kernel.functions.str | None>>
The name of the function, if not supplied, the function name will be used. Default value: None
|
description
|
<xref:<xref:semantic_kernel.functions.str | None>>
The description of the function, if not supplied, the function docstring will be used, can be None. Default value: None
|