Skip to main content

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

This is very simple to use, because it only requires a library import and a function wrapper.

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

promptcompression-0.1.3.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptcompression-0.1.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file promptcompression-0.1.3.tar.gz.

File metadata

  • Download URL: promptcompression-0.1.3.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for promptcompression-0.1.3.tar.gz
Algorithm Hash digest
SHA256 111d973fea1163ac33ea4ca15cbfc9f10267f0ba6598bd826804a58b2816d1b5
MD5 efc7ddc23461edb8075a82ed17069b0f
BLAKE2b-256 86f65e341da72dfad9b1baecaec4362e966acc9644b0105c1ead63289250a3bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptcompression-0.1.3.tar.gz:

Publisher: python-publish.yml on coreymichaud/promptcompression

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file promptcompression-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for promptcompression-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0741c74cd3290e0093c5edcc146dfc0e250508bd107494b835df53ba399c59d
MD5 22b0919822be93511bb2d836c35259a4
BLAKE2b-256 f3fe23aa68991218d80427dec7ef601b9ca09be5084fa711661b2eb260cd8dbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptcompression-0.1.3-py3-none-any.whl:

Publisher: python-publish.yml on coreymichaud/promptcompression

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page