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.1.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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for promptcompression-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f149c92fb965029775dc38dc5a6ad184d121f67c368a2b2603d2d4a7c293f7c
MD5 132f9ee520b8b514f0d500c854e62dd3
BLAKE2b-256 5e98b100639e04ea32172a3a038e5eff72dcf538920854a9c118350c544ae892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for promptcompression-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d14dbd8ab6e758a596fd2b5786717b7f7d569ddfec0672ce77555132a3b5772b
MD5 26813106193968290b3238018b705d13
BLAKE2b-256 99e26e59404354f9152aa1fab0664cfc22f43bccbe37232934ef2821989aab12

See more details on using hashes here.

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