Prompt template
PromptTemplate #
PromptTemplate(template: str)
Bases: BaseModel
Prompt Template with variable placeholders.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
str
|
Prompt template string with placeholders in {variable} format. |
Example
from beekeeper.core.prompts import PromptTemplate
# Create template
prompt = PromptTemplate(template="Summarize the following text: {input_text}")
# Format with variables
formatted = prompt.format(input_text="Hello World")
# Get template variables
variables = prompt.get_template_variables()
from_value
classmethod
#
from_value(value: str | PromptTemplate | None) -> PromptTemplate | None
Creates a PromptTemplate from different input types.
format #
format(**kwargs: Any) -> str
Formats the template using the provided variables. Missing variables are left as placeholders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Variables to substitute in the template |
{}
|
Example
prompt = PromptTemplate(template="Hello {name}, you are {age} years old")
result = prompt.format(name="Alice")
# "Hello Alice, you are {age} years old"