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

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptcompression-0.1.4.tar.gz
  • Upload date:
  • Size: 4.6 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.4.tar.gz
Algorithm Hash digest
SHA256 da443d2ce1ff9dd07f9f3bc780e1c6a4cb489d8a39adab090213e88471473848
MD5 c6f7fc58eaab2d11a862123e5d582df3
BLAKE2b-256 a3d9b223f98eb2e898dd526217806ad7db134228c863bd2230ac13025bfd0658

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for promptcompression-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 625a4faa3b9640721200eb890ff87d8d6759766ed298ef6840ef32529ded3ca6
MD5 912a6ca7586c57d8e852d9ce55acadd2
BLAKE2b-256 7bfcad2f8219167b7755a137e74d454b157e85f5b6f166def7c11ed06d320f5d

See more details on using hashes here.

Provenance

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