Skip to content

salimshre/tokenSaver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salim Token Saver

A small command-line tool for compressing prompts with LLMLingua so they use fewer tokens while keeping the important parts.

Install

Use a virtual environment so the project dependencies stay isolated.

python3 -m venv llmenv
source llmenv/bin/activate
pip install -r requirements.txt

On Windows PowerShell:

python -m venv llmenv
.\llmenv\Scripts\Activate.ps1
pip install -r requirements.txt

LLMLingua downloads its model the first time the script runs. Make sure you have an internet connection and enough free disk space.

Usage

Compress direct text:

python3 compress.py --text "Create a README file for this project." --show-stats

Compress a file:

python3 compress.py --file prompt.txt --rate 0.6

Compress from stdin:

cat prompt.txt | python3 compress.py --rate 0.7

Preserve important words or phrases:

python3 compress.py \
  --file prompt.txt \
  --force-token "API key" \
  --force-token "database,backup,production"

Options

Option Description
--text Prompt text to compress.
--file Text file containing the prompt.
--rate Fraction of tokens to keep. 0.7 keeps about 70%.
--force-token Token or comma-separated tokens that must be preserved.
--model Hugging Face model name.
--device Device map for loading the model. Default is cpu.
--show-stats Print original and compressed word counts.

Rate Guide

Rate Meaning
0.8 Light compression; keeps more of the original prompt.
0.6 Balanced compression.
0.3 Aggressive compression; review the output carefully.

About

A small command-line tool for compressing prompts with LLMLingua so they use fewer tokens while keeping the important parts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages