Skip to content

Commit

Permalink
Simplify Jinja-related docs and add some general usage tips
Browse files Browse the repository at this point in the history
  • Loading branch information
samsucik committed Mar 27, 2024
1 parent e037f85 commit 56b3b38
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,33 @@ 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
## Usage guide

### Input format

Prompterator accepts CSV files as input. Additionally, the CSV data should follow these rules:
- be parseable using a
[`pd.read_csv`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html)
call with the default argument values. This means e.g. having **column names** in the first row,
using **comma** as the separator, and enclosing values (where needed) in **double quotes** (`"`)
- have a column named `text`
### 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
Given a column named `text` in your uploaded CSV data, you can include 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 but make sure that these values are valid string representations and
are properly escaped (**double-quoted**) in your CSV file. E.g. given a column `texts` with a value
like `"[\"A\", \"B\", \"C\"]"`, you can utilise this template to enumerate the individual list items
If the values in your column represent more complex objects, you can still work with them but make
sure they are either valid JSON strings or valid Python expressions accepted by
[`ast.literal_eval`](https://docs.python.org/3/library/ast.html#ast.literal_eval).
To parse string representations of objects, use:
- `fromjson`: for valid JSON strings, e.g. `'["A", "B"]'`
- `fromAstString`: for Python expressions such as dicts/lists/tuples/... (see the accepted types of
[`ast.literal_eval`](https://docs.python.org/3/library/ast.html#ast.literal_eval)), e.g. `"{'key': 'value'}"`
For example, given a CSV column `texts` with a value `"[""A"", ""B"", ""C""]"`, you can utilise this template to enumerate the individual list items
in your prompt:
```jinja
{% for item in fromjson(texts) -%}
Expand All @@ -133,13 +150,6 @@ which would lead to this in your prompt:
- C
```
To parse objects from their string representation like in the above example, we provide two
functions you can use in your templates:
- `fromjson`: to be used only in case of _valid JSON strings_
- `fromAstString`: to parse a wider range of string representations (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 56b3b38

Please sign in to comment.