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

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.2.tar.gz (4.7 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.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptcompression-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 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.2.tar.gz
Algorithm Hash digest
SHA256 c2b73d5d5564eb009aebb35d12e2df5cb2d78c4bbf4b19f9d568f067932d7d2c
MD5 e757ab2f18ca51c22de9683ce2c114ab
BLAKE2b-256 318c780398c1f495261131c11a8590e2d146cf24d839c7b1d2c3cde4b984fcca

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptcompression-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for promptcompression-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55e56d9752913bae15e1562b7b8b28c5fc8b4f5a1a7f19c7a501d97e9f940cd8
MD5 9a23f430a171205733eb5e28de0273a6
BLAKE2b-256 1d69cc20bd4d150671b74bbcab0cc868c736f56697e2788665e5fb33236c06bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptcompression-0.1.2-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