Skip to main content

Self-extracting GPT prompts for ~70% token savings.

Project description

CompressGPT

Self-extracting GPT prompts for ~70% token savings

Check out the accompanying blog post here.

Installation

$ pip install compress-gpt

Usage

Simply change your existing imports of langchain.PromptTemplate to compress_gpt.langchain.CompressTemplate (to compress prompts before populating variables) or compress_gpt.langchain.CompressPrompt (to compress prompts after populating variables).

-from langchain import PromptTemplate
+from compress_gpt.langchain import CompressPrompt as PromptTemplate

For very simple prompts, use CompressSimplePrompt and CompressSimpleTemplate instead.

If compression ever fails or results in extra tokens, the original prompt will be used. Each compression result is aggressively cached, but the first run can take a hot sec.

Clearing the cache

import compress_gpt

compress_gpt.clear_cache()

Demo

asciicast

How CompressGPT Works

My blog post helps explain the below image.

CompressGPT Pipeline

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

compress_gpt-0.1.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

compress_gpt-0.1.2-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: compress_gpt-0.1.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/5.15.0-1035-azure

File hashes

Hashes for compress_gpt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6c1f1e33840bf0c82418318f7b7458beec2aca0f595db17fdd9b37a0bbaea9c8
MD5 f8f26dbe4da5da3760ca0b6ab580cff4
BLAKE2b-256 c95ee9953ab9b3efc175281dc64656db0836c2ba2a805ab7153a6ab6ce45902e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: compress_gpt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/5.15.0-1035-azure

File hashes

Hashes for compress_gpt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da6347c666085dbf1e1bad659e540e7e53a083b25010ac59f24861075be686e6
MD5 c2997e8900c095f2cc3f6a2ecae54bfb
BLAKE2b-256 eecdeeda9c47a02f5b9880f878e313f15fefb2fdf11d874dedbef25698d5b7b8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page