Skip to content

Commit

Permalink
Add brief documentation in README for using Jinja templates in prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
samsucik committed Mar 27, 2024
1 parent 6039527 commit 8d83e64
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ The image will be rendered inside the displayed dataframe and next to the "gener

(*Note: you also need an `OPENAI_API_KEY` environment variable to use `gpt-4-vision-preview`*)

## Using input data in prompts

The user/system prompt textboxes support [Jinja](https://jinja.palletsprojects.com/) templates.
Given a column named `text` in your uploaded CSV data, you can use values from this column by
writing the simple `{{text}}` template in your prompt.

If the values in your column represent more complex objects such as Python dictionaries or lists,
you can still work with them. E.g. given a column `texts` with a value like `'["A", "B",
C"]'`, you can utilise this template to enumerate the individual list items in your prompt:
```jinja
{% for item in fromjson(texts) %}
- {{ item }}
{% endfor %}
```

To parse objects from their string representation, we provide two functions you can use in your
templates:
- `fromjson`: to be used in case of _valid JSON strings_ (like above)
- `fromAstString`: to parse a wider range of string representation (it's based on
[`ast.literal_eval`](https://docs.python.org/3/library/ast.html#ast.literal_eval))


## Paper

You can find more information on Prompterator in the associated paper: https://aclanthology.org/2023.emnlp-demo.43/
Expand Down

0 comments on commit 8d83e64

Please sign in to comment.