Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.62 KB

README.md

File metadata and controls

57 lines (39 loc) · 1.62 KB

Prompts Logo

.txt Twitter

Contributors Discord

A prompting library.

Made with ❤👷️ by the team at .txt.

Prompt functions

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)