The template
decorator takes a function as an argument whose docstring is a Jinja template, and returns a Template
object:
from prompts import template
@template
def few_shots(instructions, examples, question):
return """{{ instructions }}
Examples
--------
{% for example in examples %}
Q: {{ example.question }}
A: {{ example.answer }}
{% endfor %}
Q: {{ question}}
A: """
Calling the Template
object renders the Jinja template:
instructions = "Please answer the following question following the examples" examples = [
{"question": "2+2=?", "answer":4},
{"question": "3+3=?", "answer":6},
]
question = "4+4 = ?"
prompt = few_shots(instructions, examples, question)