Skip to main content

Token-saving abbreviation compressor for OpenAI LLM prompts

Project description

abbrcompress

Token-saving abbreviation compression for OpenAI-compatible LLM prompts.

abbrcompress identifies frequently repeated phrases in a prompt, replaces them with short abbreviations, and decodes the model response back to the original text — helping reduce token usage for long or repetitive prompts.


Install

pip install abbrcompress
# or
uv pip install abbrcompress

Usage

from abbrcompress.core import build_abbreviations, compress_prompt, decode_abbreviations, token_len

prompt = """your prompt text here"""

# Build abbreviation dictionary
abbr_dict, _ = build_abbreviations(prompt)

# Compress prompt
compressed_prompt = compress_prompt(prompt, abbr_dict)

# TODO: send compressed_prompt to OpenAI and get return_message as response
return_message = _  # Placeholder for OpenAI response

# Decode return from OpenAI
decoded_text = decode_abbreviations(return_message, abbr_dict)

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

abbrcompress-0.1.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

abbrcompress-0.1.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abbrcompress-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for abbrcompress-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0cc9e1a40d36f115b8fa5e34f14b8fb563a4177114309e2516f6585ecccaba3d
MD5 fd18d6abc181eb4c4d1bff1178cec26e
BLAKE2b-256 0c2f7352c3b33e9040467c84fddb9b47f2633d09685bf2a1f3c0c10a5dcf10ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: abbrcompress-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for abbrcompress-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3f3b16e9f1f12355566069ea667f5099ed4a1d909b236bf112ad258174ee7bb5
MD5 3badc526856af0c622f0c7329ea64328
BLAKE2b-256 29db93e5927309b7eca7fdfbe382d1d9d53044cf83d8db4391cccd2ac8b9f4d7

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