interpolate
interpolate(prompt, *, variables=None, variable_start='{{', variable_end='}}')Interpolate variables into a prompt
This is a light-weight wrapper around the Jinja2 templating engine, making it easier to interpolate dynamic data into a prompt template. Compared to f-strings, which expects you to wrap dynamic values in { }, this function expects {{ }} instead, making it easier to include Python code and JSON in your prompt.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| prompt | str | The prompt to interpolate (as a string). | required |
| variables | Optional[dict[str, Any]] | A dictionary of variables to interpolate into the prompt. If not provided, the caller’s global and local variables are used. | None |
| variable_start | str | The string that marks the beginning of a variable. | '{{' |
| variable_end | str | The string that marks the end of a variable. | '}}' |
Returns
| Name | Type | Description |
|---|---|---|
| str | The prompt with variables interpolated. |
Examples
from chatlas import interpolate
x = 1
interpolate("The value of `x` is: {{ x }}")