Skip to content
GitHub Login

Prompt Templating

This guide will show you how to use templates in your prompts, pass custom input parameters, and create new contexts as they are chained together. We will use the Jinja2 template language for this purpose.

Jinja2 is a powerful templating engine for Python. It allows you to create dynamic prompts by embedding logic within your templates.

Here is a basic example of a Jinja2 template:

from jinja2 import Template
# Define a Jinja2 template
template = Template("You are a comedian. Tell me a joke about {{ topic }}.")
# Render the template with a specific topic
rendered_prompt = template.render(topic="chickens")
print(rendered_prompt)