Compare prompts in Python with clear, pretty-printed output.
Project description
pretty_prompt_compare
A python package for comparing prompts/responses with pretty print.
https://github.com/user-attachments/assets/ef152000-a954-4e3e-ad05-47f840d0db09
In the age of LLMs, a lot of prompt engineering comes down to comparing prompts and their responses. This Python package helps by pretty-printing pairs of prompts and responses, making it easier to see differences and embed this workflow into your Python development environment.
Installation
pip install pretty_prompt_compare
Usage
[!IMPORTANT]
This project leverages a parameterized infix operator (|PrettyCompare|) to simplify comparing prompts/responses using readable syntax.
-
To compare prompts, use the
compare_prompt=Trueargument. The prompt will be printed in the console with differences highlighted, and f-string expressions shown in a different color.from pretty_prompt_compare import PrettyCompare # to compare differences in prompts pretty_compare = PrettyCompare(compare_prompt=True) "Hello beautiful {world}" |pretty_compare| "Hello brave {world}"
The two prompts on either side of the
|pretty_compare|operation will be printed using the following format:- {first prompt} + {second prompt}
If
print_separator=True, a separator line will be printed between the two prompts.In the printed second prompt:
- Characters that appear only in the first prompt will be highlighted using
COLOR_PALETTE["delete"]and shown with astrikethrough. - Characters that appear only in the second prompt will be highlighted using
COLOR_PALETTE["insert"].
In both prompts, the
{f-string expressions}will be highlighted in value ofCOLOR_PALETTE["f-string expression"]. - Characters that appear only in the first prompt will be highlighted using
-
To compare responses, use the
compare_response=Trueargument. The responses will be printed in the console with differences highlighted, and target strings highlighted in a different color.from pretty_prompt_compare import PrettyCompare # to compare differences in responses pretty_compare = PrettyCompare(compare_response=True, target=["brave", "beautiful", "world"]) "Hello beautiful {world}" |pretty_compare| "Hello brave {world}"
The responses are displayed in a similar format to the prompts, with the additional feature that target strings are highlighted using
COLOR_PALETTE["focus"]with underline and bold. -
To Change the color palette, use the
color_paletteargument.# compare differences in prompts with custom color palette pretty_compare = PrettyCompare(compare_prompt=True, color_palette=...)
The default color palette can be found at https://github.com/com3dian/pretty_prompt_compare/blob/7cbad091065d0b962fb7288b090333bc95ede305/src/pretty_prompt_compare.py#L34-L40
Note
The prompts/responses are compared using the difflib.SequenceMatcher class. The algorithm for text comparison is based on the Ratcliff/Obershelp pattern recognition algorithm. For more reference please visit https://docs.python.org/3/library/difflib.html#difflib.SequenceMatcher.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pretty_prompt_compare-0.0.2.tar.gz.
File metadata
- Download URL: pretty_prompt_compare-0.0.2.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
002db12d187138e4d124c2fe9dded8fb5e180591f0838687e629b8176065fc89
|
|
| MD5 |
1d0c914a3f7b02e8623af1c06e9832a2
|
|
| BLAKE2b-256 |
8f224ad1cfdf21cb32dded81d10f383b53d95a575440fee8d9f7ca031b9e90a5
|
File details
Details for the file pretty_prompt_compare-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pretty_prompt_compare-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
541994a55850eb406e45ae5ea05c9d4b24b04ac5f19e6a6a14fb0c2b9fafeab1
|
|
| MD5 |
a0e927fd7a89c6182ff5a952e3a5785a
|
|
| BLAKE2b-256 |
d903c2964dbf2dc984f04623dce41faa79ed4e1902008ceceaeb7489523f811a
|