KernelPromptTemplate Class
Create a Kernel prompt template.
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.
Constructor
KernelPromptTemplate(*, prompt_template_config: PromptTemplateConfig, allow_dangerously_set_content: bool = False)
Keyword-Only Parameters
Name | Description |
---|---|
prompt_template_config
Required
|
|
allow_dangerously_set_content
Required
|
|
Methods
extract_blocks |
Given the prompt template, extract all the blocks (text, variables, function calls). |
model_post_init |
We need to both initialize private attributes and call the user-defined model_post_init method. |
quick_render |
Quick render a Kernel prompt template, only supports text and variable blocks. |
render |
Render the prompt template. Using the prompt template, replace the variables with their values and execute the functions replacing their reference with the function result. |
render_blocks |
Given a list of blocks render each block and compose the final result. |
validate_template_format |
Validate the template format. |
extract_blocks
Given the prompt template, extract all the blocks (text, variables, function calls).
extract_blocks() -> list[Block]
model_post_init
We need to both initialize private attributes and call the user-defined model_post_init method.
model_post_init(context: Any, /) -> None
Positional-Only Parameters
Name | Description |
---|---|
context
Required
|
|
quick_render
Quick render a Kernel prompt template, only supports text and variable blocks.
static quick_render(template: str, arguments: dict[str, Any]) -> str
Parameters
Name | Description |
---|---|
template
Required
|
The template to render |
arguments
Required
|
The arguments to use for rendering |
Returns
Type | Description |
---|---|
The prompt template ready to be used for an AI request |
render
Render the prompt template.
Using the prompt template, replace the variables with their values and execute the functions replacing their reference with the function result.
async render(kernel: Kernel, arguments: KernelArguments | None = None) -> str
Parameters
Name | Description |
---|---|
kernel
Required
|
<xref:<xref:semantic_kernel.prompt_template.kernel_prompt_template."Kernel">>
The kernel to use for functions. |
arguments
Required
|
<xref:<xref:semantic_kernel.prompt_template.kernel_prompt_template."KernelArguments | None">>
The arguments to use for rendering. (Default value = None) Default value: None
|
Returns
Type | Description |
---|---|
The prompt template ready to be used for an AI request |
render_blocks
Given a list of blocks render each block and compose the final result.
async render_blocks(blocks: list[Block], kernel: Kernel, arguments: KernelArguments | None = None) -> str
Parameters
Name | Description |
---|---|
blocks
Required
|
list[<xref:Block>]
Template blocks generated by ExtractBlocks |
kernel
Required
|
<xref:<xref:semantic_kernel.prompt_template.kernel_prompt_template."Kernel">>
The kernel to use for functions |
arguments
Required
|
<xref:<xref:semantic_kernel.prompt_template.kernel_prompt_template."KernelArguments | None">>
The arguments to use for rendering (Default value = None) Default value: None
|
Returns
Type | Description |
---|---|
The prompt template ready to be used for an AI request |
validate_template_format
Validate the template format.
validate_template_format(v: PromptTemplateConfig) -> PromptTemplateConfig
Parameters
Name | Description |
---|---|
v
Required
|
|
Attributes
allow_dangerously_set_content
allow_dangerously_set_content: bool
prompt_template_config
prompt_template_config: PromptTemplateConfig