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 compressed_text as response
compressed_text = _  # Placeholder for OpenAI response

# Decode return from OpenAI
decoded_text = decode_abbreviations(compressed_text, 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.2.tar.gz (4.4 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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abbrcompress-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 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.2.tar.gz
Algorithm Hash digest
SHA256 c466b512d35245998905877d08f3fc722c319ad07fa33f847b84e737d1bcb443
MD5 341a4d769bb599ca5a43b9d5a6993e40
BLAKE2b-256 eac1d9b8a33f1dca98d7c928665e43a1cefb914d6c4a0c66709a6df79649d536

See more details on using hashes here.

File details

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

File metadata

  • Download URL: abbrcompress-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93595498cc74c8eb8f61aafa6da8c14b6cbea3dfb626a8c63d7a37d754ae01d0
MD5 2d00c64e868d7f05d4873474869e6419
BLAKE2b-256 2e4b4e5e3c9957a66d348c234fbd3bb5cd628b534eeeaf506df165f07a89a4a6

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