Prompt Templating
Introduction
Section titled “Introduction”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.
Using Jinja2 Templates
Section titled “Using Jinja2 Templates”Jinja2 is a powerful templating engine for Python. It allows you to create dynamic prompts by embedding logic within your templates.
Basic Example
Section titled “Basic Example”Here is a basic example of a Jinja2 template:
from jinja2 import Template
# Define a Jinja2 templatetemplate = Template("You are a comedian. Tell me a joke about {{ topic }}.")
# Render the template with a specific topicrendered_prompt = template.render(topic="chickens")
print(rendered_prompt)