Share via


KernelFunctionFromPrompt Class

Semantic Kernel Function from a prompt.

Initializes a new instance of the KernelFunctionFromPrompt class.

Constructor

KernelFunctionFromPrompt(function_name: str, plugin_name: str | None = None, description: str | None = None, prompt: str | None = None, template_format: Literal['semantic-kernel', 'handlebars', 'jinja2'] = 'semantic-kernel', prompt_template: PromptTemplateBase | None = None, prompt_template_config: PromptTemplateConfig | None = None, prompt_execution_settings: PromptExecutionSettings | Sequence[PromptExecutionSettings] | Mapping[str, PromptExecutionSettings] | None = None)

Parameters

Name Description
function_name
Required
str

The name of the function

plugin_name
str

The name of the plugin

Default value: None
description
str

The description for the function

Default value: None
prompt
<xref:Optional>[str]

The prompt

Default value: None
template_format
<xref:Optional>[str]

The template format, default is "semantic-kernel"

Default value: semantic-kernel
prompt_template
<xref:Optional>[<xref:KernelPromptTemplate>]

The prompt template

Default value: None
prompt_template_config
<xref:Optional>[<xref:PromptTemplateConfig>]

The prompt template configuration

Default value: None
prompt_execution_settings

instance, list or dict of PromptExecutionSettings to be used by the function, can also be supplied through prompt_template_config, but the supplied one is used if both are present. prompt_template_config (Optional[PromptTemplateConfig]): the prompt template config.

Default value: None

Methods

from_directory

Creates a new instance of the KernelFunctionFromPrompt class from a directory.

The directory needs to contain:

  • A prompt file named skprompt.txt
  • A config file named config.json
from_yaml

Creates a new instance of the KernelFunctionFromPrompt class from a YAML string.

rewrite_execution_settings

Rewrite execution settings to a dictionary.

If the prompt_execution_settings is not a dictionary, it is converted to a dictionary. If it is not supplied, but prompt_template is, the prompt_template's execution settings are used.

update_arguments_with_defaults

Update any missing values with their defaults.

from_directory

Creates a new instance of the KernelFunctionFromPrompt class from a directory.

The directory needs to contain:

  • A prompt file named skprompt.txt
  • A config file named config.json
from_directory(path: str, plugin_name: str | None = None) -> KernelFunctionFromPrompt

Parameters

Name Description
path
Required
plugin_name
Default value: None

Returns

Type Description

The kernel function from prompt

from_yaml

Creates a new instance of the KernelFunctionFromPrompt class from a YAML string.

from_yaml(yaml_str: str, plugin_name: str | None = None) -> KernelFunctionFromPrompt

Parameters

Name Description
yaml_str
Required
plugin_name
Default value: None

rewrite_execution_settings

Rewrite execution settings to a dictionary.

If the prompt_execution_settings is not a dictionary, it is converted to a dictionary. If it is not supplied, but prompt_template is, the prompt_template's execution settings are used.

rewrite_execution_settings(data: Any) -> dict[str, PromptExecutionSettings]

Parameters

Name Description
data
Required

update_arguments_with_defaults

Update any missing values with their defaults.

update_arguments_with_defaults(arguments: KernelArguments) -> None

Parameters

Name Description
arguments
Required

Attributes

invocation_duration_histogram

invocation_duration_histogram: metrics.Histogram

metadata

metadata: KernelFunctionMetadata

prompt_execution_settings

prompt_execution_settings: dict[str, PromptExecutionSettings]

prompt_template

prompt_template: PromptTemplateBase

streaming_duration_histogram

streaming_duration_histogram: metrics.Histogram