Taking text input and compressing it into a smaller representation for cost savings.
Project description
LLM Prompt Compression
Are LLM's costing you too much in your application? This library will allow your prompts to have the minimum amount of text needed to convey what you want the LLM to do. This is perfect for prompts given by users, where they are constantly eating at your costs.
What is this suitable for?
- Chat bots
- Local LLMS
- Input that does not need to have a strict structure
- Reducing text which reduces tokens which reduces $$$
What is this not suitable for?
- Code
- Math
- Inputs that require structure, like reviewing a writing sample
Install
This package is available on PyPI:
$ pip install promptcompression
Usage
You use the compress() function, which has the argument text for the input prompt, and the optional argument savings which, when True, returns a tuple of the number of tokens saved, and the ratio of tokens saved by the original tokens.
Example:
from promptcompression import compress
prompt, tokens, ratio = compress("Summarize this text while sounding more natural. Please do not use contractions or an em dash to be more human-like.", savings = True)
print("Compressed text:", prompt)
print("Tokens saved:", tokens)
print(f"Compression ratio: {ratio:.2f}")
>>> Compressed text: summar text sound natur pleas dont use contract em dash humanlik
>>> Tokens saved: 13
>>> Compression ratio: 0.50
If you want to learn more...
... please check out the markdown file PROCESS.md, where I explain my process throught the project. This is located in the library's GitHub repo.
Project details
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 promptcompression-0.1.0.tar.gz.
File metadata
- Download URL: promptcompression-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11d2791d74dc6353d7b7b7a44a80f11ce2936e0df07b01002fb567efd5d6406d
|
|
| MD5 |
82b306ad96f6f08cba156c71ab1f9ad5
|
|
| BLAKE2b-256 |
211a8553c5fc9f02a752cc13fd9cf59d666fd310d38dbf097fc560fc6afd2d2e
|
File details
Details for the file promptcompression-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptcompression-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c321e6451c09eec5db2948bdb09f24bbef27ffe9cb56d9afc5ac8f1ee1ae02b
|
|
| MD5 |
674ad5498ec0bb2ad98db3f0f1e0a68d
|
|
| BLAKE2b-256 |
07883769295cef9cc73f43d596698a8f0d6707cc925f40072df1d981392d645c
|