llm-zip 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm_zip-0.1.0/LICENSE +21 -0
- llm_zip-0.1.0/PKG-INFO +311 -0
- llm_zip-0.1.0/README.md +254 -0
- llm_zip-0.1.0/llm_zip.egg-info/PKG-INFO +311 -0
- llm_zip-0.1.0/llm_zip.egg-info/SOURCES.txt +50 -0
- llm_zip-0.1.0/llm_zip.egg-info/dependency_links.txt +1 -0
- llm_zip-0.1.0/llm_zip.egg-info/entry_points.txt +2 -0
- llm_zip-0.1.0/llm_zip.egg-info/requires.txt +19 -0
- llm_zip-0.1.0/llm_zip.egg-info/top_level.txt +1 -0
- llm_zip-0.1.0/llmzip/__init__.py +7 -0
- llm_zip-0.1.0/llmzip/api/__init__.py +3 -0
- llm_zip-0.1.0/llmzip/api/app.py +72 -0
- llm_zip-0.1.0/llmzip/api/dependencies.py +16 -0
- llm_zip-0.1.0/llmzip/api/routes/__init__.py +2 -0
- llm_zip-0.1.0/llmzip/api/routes/compress.py +138 -0
- llm_zip-0.1.0/llmzip/api/routes/compress_file.py +104 -0
- llm_zip-0.1.0/llmzip/api/routes/health.py +22 -0
- llm_zip-0.1.0/llmzip/api/routes/models.py +28 -0
- llm_zip-0.1.0/llmzip/api/schemas.py +74 -0
- llm_zip-0.1.0/llmzip/cli/__init__.py +3 -0
- llm_zip-0.1.0/llmzip/cli/compress_cmd.py +237 -0
- llm_zip-0.1.0/llmzip/cli/download_models.py +149 -0
- llm_zip-0.1.0/llmzip/cli/main.py +30 -0
- llm_zip-0.1.0/llmzip/cli/prices_cmd.py +142 -0
- llm_zip-0.1.0/llmzip/config/__init__.py +3 -0
- llm_zip-0.1.0/llmzip/config/loader.py +106 -0
- llm_zip-0.1.0/llmzip/conversion/__init__.py +13 -0
- llm_zip-0.1.0/llmzip/conversion/file_converter.py +73 -0
- llm_zip-0.1.0/llmzip/core/__init__.py +13 -0
- llm_zip-0.1.0/llmzip/core/lingua_adapter.py +85 -0
- llm_zip-0.1.0/llmzip/core/savings_calculator.py +63 -0
- llm_zip-0.1.0/llmzip/core/semantic_scorer.py +60 -0
- llm_zip-0.1.0/llmzip/core/token_counter.py +50 -0
- llm_zip-0.1.0/llmzip/i18n/__init__.py +84 -0
- llm_zip-0.1.0/llmzip/i18n/en.py +61 -0
- llm_zip-0.1.0/llmzip/i18n/es.py +61 -0
- llm_zip-0.1.0/llmzip/i18n/ja.py +61 -0
- llm_zip-0.1.0/llmzip/i18n/pt.py +61 -0
- llm_zip-0.1.0/llmzip/i18n/zh.py +61 -0
- llm_zip-0.1.0/llmzip/pricing/__init__.py +8 -0
- llm_zip-0.1.0/llmzip/pricing/fallback.py +29 -0
- llm_zip-0.1.0/llmzip/pricing/fetcher.py +49 -0
- llm_zip-0.1.0/llmzip/pricing/resolver.py +42 -0
- llm_zip-0.1.0/pyproject.toml +74 -0
- llm_zip-0.1.0/setup.cfg +4 -0
- llm_zip-0.1.0/tests/test_compress_cmd.py +131 -0
- llm_zip-0.1.0/tests/test_file_converter.py +65 -0
- llm_zip-0.1.0/tests/test_loader.py +65 -0
- llm_zip-0.1.0/tests/test_resolver.py +30 -0
- llm_zip-0.1.0/tests/test_savings_calculator.py +58 -0
- llm_zip-0.1.0/tests/test_semantic_scorer.py +41 -0
- llm_zip-0.1.0/tests/test_token_counter.py +33 -0
llm_zip-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FinkTech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
llm_zip-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-zip
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Context compression sidecar for LLM applications. Reduce token costs 3-5x before calling any AI API.
|
|
5
|
+
Author-email: "Ariel A. Fink" <hello.finksystems@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 FinkTech
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Keywords: llm,context-compression,token-optimization,fastapi,llmlingua,rag,ai-cost-reduction
|
|
28
|
+
Classifier: Development Status :: 3 - Alpha
|
|
29
|
+
Classifier: Intended Audience :: Developers
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
35
|
+
Requires-Python: >=3.10
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
License-File: LICENSE
|
|
38
|
+
Requires-Dist: llmlingua>=0.2.2
|
|
39
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
40
|
+
Requires-Dist: markitdown[all]>=0.1.0
|
|
41
|
+
Requires-Dist: fastapi>=0.115.0
|
|
42
|
+
Requires-Dist: uvicorn[standard]>=0.30.0
|
|
43
|
+
Requires-Dist: pydantic>=2.0.0
|
|
44
|
+
Requires-Dist: python-multipart>=0.0.9
|
|
45
|
+
Requires-Dist: typer>=0.12.0
|
|
46
|
+
Requires-Dist: tiktoken>=0.7.0
|
|
47
|
+
Requires-Dist: httpx>=0.27.0
|
|
48
|
+
Requires-Dist: questionary>=2.0.0
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
|
|
53
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
54
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
55
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
# 🗜️ llm-zip
|
|
59
|
+
|
|
60
|
+
<p align="center">
|
|
61
|
+
<a href="https://github.com/finktech-dev/llm-zip/releases"><img src="https://img.shields.io/badge/version-0.1.0-blue?style=for-the-badge" alt="Version"></a>
|
|
62
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-22c55e?style=for-the-badge" alt="License"></a>
|
|
63
|
+
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python"></a>
|
|
64
|
+
<a href="https://fastapi.tiangolo.com/"><img src="https://img.shields.io/badge/API-FastAPI-009688?style=for-the-badge&logo=fastapi&logoColor=white" alt="FastAPI"></a>
|
|
65
|
+
<a href="https://www.docker.com/"><img src="https://img.shields.io/badge/Docker-ready-2496ED?style=for-the-badge&logo=docker&logoColor=white" alt="Docker"></a>
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
<p align="center">
|
|
69
|
+
<a href="https://github.com/microsoft/LLMLingua"><img src="https://img.shields.io/badge/Powered_by-LLMLingua--2-FF6F00?style=flat-square&logo=microsoft&logoColor=white" alt="LLMLingua-2"></a>
|
|
70
|
+
<a href="https://github.com/microsoft/markitdown"><img src="https://img.shields.io/badge/Files_via-MarkItDown-0078D4?style=flat-square&logo=microsoft&logoColor=white" alt="MarkItDown"></a>
|
|
71
|
+
<a href="https://github.com/BerriAI/litellm"><img src="https://img.shields.io/badge/Pricing-LiteLLM-7C3AED?style=flat-square&logo=github&logoColor=white" alt="LiteLLM"></a>
|
|
72
|
+
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square" alt="Ruff"></a>
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
<p align="center">
|
|
76
|
+
<strong>Context compression sidecar for LLM applications.<br>Reduce token costs 3–5× before calling any AI API.</strong>
|
|
77
|
+
</p>
|
|
78
|
+
|
|
79
|
+
<p align="center">
|
|
80
|
+
<a href="#why-llm-zip-exists">Why</a> ·
|
|
81
|
+
<a href="#how-it-works">How it works</a> ·
|
|
82
|
+
<a href="#quickstart">Quickstart</a> ·
|
|
83
|
+
<a href="#the-cli-experience">CLI</a> ·
|
|
84
|
+
<a href="#what-you-get-back">API response</a> ·
|
|
85
|
+
<a href="#markitdown-integration">File support</a> ·
|
|
86
|
+
<a href="#-the-science--benchmarks">Benchmarks</a> ·
|
|
87
|
+
<a href="#limitations--caveats">Limitations</a> ·
|
|
88
|
+
<a href="#contributing">Contributing</a>
|
|
89
|
+
</p>
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Why llm-zip exists
|
|
94
|
+
|
|
95
|
+
AI inference is getting expensive. As context windows grow and agentic workflows multiply, the tokens you send to GPT, Claude, or Gemini compound fast — and the "free ride" subsidy era is ending.
|
|
96
|
+
|
|
97
|
+
llm-zip was built out of a simple need: compress context before it reaches the model, without changing anything else in the stack. No proxy. No middleware. No API keys. Just a sidecar you call over HTTP, that hands back a smaller text and tells you exactly how much you saved.
|
|
98
|
+
|
|
99
|
+
It started as an internal tool. It's open source because the problem is universal.
|
|
100
|
+
|
|
101
|
+
> Curious about how this started? Read [STORY.md](STORY.md).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## How it works
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
Your app ──→ POST /v1/compress ──→ llm-zip
|
|
109
|
+
│
|
|
110
|
+
compresses with LLMLingua-2
|
|
111
|
+
scores semantic preservation
|
|
112
|
+
calculates USD savings
|
|
113
|
+
│
|
|
114
|
+
compressed text + metrics ◄─┘
|
|
115
|
+
|
|
116
|
+
Your app ──→ calls OpenAI / Anthropic / Gemini
|
|
117
|
+
with the smaller context
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
llm-zip never touches your API keys or your model calls. It only compresses.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Quickstart
|
|
125
|
+
|
|
126
|
+
> **Requires Docker.** First-time model download is ~700MB and takes 2–5 min.
|
|
127
|
+
|
|
128
|
+
**Step 1 — Configure**
|
|
129
|
+
|
|
130
|
+
Windows (CMD / PowerShell):
|
|
131
|
+
```powershell
|
|
132
|
+
copy .llmzip.config.example .llmzip.config
|
|
133
|
+
notepad .llmzip.config
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Linux / macOS:
|
|
137
|
+
```bash
|
|
138
|
+
cp .llmzip.config.example .llmzip.config
|
|
139
|
+
nano .llmzip.config
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Step 2 — Download models** *(only on first run)*
|
|
143
|
+
```bash
|
|
144
|
+
docker-compose run llmzip download-models
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Step 3 — Start**
|
|
148
|
+
```bash
|
|
149
|
+
docker-compose up -d
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
→ API: `http://localhost:8000` · Docs: `http://localhost:8000/docs`
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## The CLI Experience
|
|
157
|
+
|
|
158
|
+
llm-zip isn't just an API — it comes with a UNIX-friendly CLI powered by Typer and Rich. It supports `stdin` pipes, outputs clean JSON, and tracks live model prices.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Check current prices (fetches live from LiteLLM)
|
|
162
|
+
$ llmzip prices -p anthropic
|
|
163
|
+
|
|
164
|
+
Rates from LiteLLM as of 2026-06-05
|
|
165
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
|
|
166
|
+
┃ Model ┃ Input $/M ┃ Output $/M ┃
|
|
167
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
|
|
168
|
+
│ anthropic.claude-3-5-sonnet-20241022-v2:0 │ 3.0000 │ 15.0000 │
|
|
169
|
+
│ anthropic.claude-3-haiku-20240307-v1:0 │ 0.2500 │ 1.2500 │
|
|
170
|
+
└───────────────────────────────────────────┴───────────┴────────────┘
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
> Model names come directly from LiteLLM and may use provider-specific naming (e.g. Bedrock-style). The exact list depends on live data at execution time.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Compress directly from the terminal via pipes
|
|
177
|
+
$ cat huge_context.txt | llmzip compress --ratio 0.4 --model gpt-4o-mini > compressed.txt
|
|
178
|
+
✓ 24000 → 9600 tokens (2.5×) | score: 0.92 | saved: ~$0.0021 (gpt-4o-mini)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## What you get back
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"compressed": "...",
|
|
188
|
+
"original_tokens": 8400,
|
|
189
|
+
"compressed_tokens": 1680,
|
|
190
|
+
"compression_ratio": 5.0,
|
|
191
|
+
"preservation_score": 0.91,
|
|
192
|
+
"estimated_savings": {
|
|
193
|
+
"gpt-4o-mini": "$0.0010",
|
|
194
|
+
"claude-haiku-4-5": "$0.0013",
|
|
195
|
+
"gemini-2.5-flash-lite": "$0.0006"
|
|
196
|
+
},
|
|
197
|
+
"skipped": false,
|
|
198
|
+
"warning": null
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Prices are fetched live from [LiteLLM](https://github.com/BerriAI/litellm) with local caching — no manual database updates needed.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## MarkItDown Integration
|
|
207
|
+
|
|
208
|
+
One of the practical problems that motivated llm-zip was RAG over internal documents. In private systems — invoices, reports, manuals, internal specs — the source content lives in PDFs, Word files, and spreadsheets.
|
|
209
|
+
|
|
210
|
+
llm-zip integrates [MarkItDown](https://github.com/microsoft/markitdown) as an optional preprocessing layer. When `FILE_CONVERSION=true`, you can send a file directly to `/v1/compress/file` and get back compressed text ready for your RAG pipeline.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
curl -X POST http://localhost:8000/v1/compress/file \
|
|
214
|
+
-F "file=@invoice.pdf" \
|
|
215
|
+
-F "ratio=0.5"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Supported formats: PDF, Word (`.docx`), Excel (`.xlsx`), PowerPoint (`.pptx`), and more.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Key Features
|
|
223
|
+
|
|
224
|
+
| | Feature | Detail |
|
|
225
|
+
|---|---|---|
|
|
226
|
+
| 📄 | **Text and files** | Compress plain text or upload PDFs, Word, Excel, and PowerPoint directly |
|
|
227
|
+
| 🖥️ | **CPU-Friendly** | Default model requires only ~700MB of RAM — no GPU needed |
|
|
228
|
+
| 🌐 | **Global i18n** | CLI in English, Spanish, Portuguese, Chinese, and Japanese |
|
|
229
|
+
| ⚙️ | **Configurable thresholds** | Define when llm-zip should and shouldn't intervene (`MIN_TOKENS_TO_COMPRESS`) |
|
|
230
|
+
| 🚫 | **Ignore rules** | Exclude texts or system prompts via `.llmzipignore` and `.llmzipignore.local` |
|
|
231
|
+
| 🔒 | **Self-hosted** | Your data never leaves your infrastructure |
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Environment Variables
|
|
236
|
+
|
|
237
|
+
For CI or Docker deployments, you can override defaults with environment variables:
|
|
238
|
+
|
|
239
|
+
| Variable | Description |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `LLMZIP_LANG` | Forces CLI language (`en`, `es`, `pt`, `zh`, `ja`). Overrides system locale. |
|
|
242
|
+
| `MODELS_URL` | Overrides internal DNS for the models container. Defaults to `http://llmzip-models:8001`. |
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 📊 The Science & Benchmarks
|
|
247
|
+
|
|
248
|
+
llm-zip is powered by Microsoft's LLMLingua-2. According to their [research paper evaluated on the LongBench dataset](https://arxiv.org/abs/2403.12968):
|
|
249
|
+
|
|
250
|
+
- **Compression sweet spot:** optimal performance between **2× and 5× compression**
|
|
251
|
+
- **Quality retention:** **90–98% Exact Match performance** vs. uncompressed prompts
|
|
252
|
+
- **Latency reduction:** end-to-end latency improvement of **1.6× to 2.9×** (task-agnostic, no prompt needed to start)
|
|
253
|
+
|
|
254
|
+
<details>
|
|
255
|
+
<summary>📋 Hardware benchmarks (click to expand)</summary>
|
|
256
|
+
|
|
257
|
+
> **Community-maintained — no verified numbers yet.**
|
|
258
|
+
> If you run llm-zip on real hardware, please submit your results via PR. Include: hardware, model (`bert-base` or `xlm-roberta-large`), input token count, and time to compress.
|
|
259
|
+
|
|
260
|
+
| Hardware | Model | Input Tokens | Time to Compress |
|
|
261
|
+
| :------- | :---- | :----------- | :--------------- |
|
|
262
|
+
| — | — | — | — |
|
|
263
|
+
|
|
264
|
+
</details>
|
|
265
|
+
|
|
266
|
+
<details>
|
|
267
|
+
<summary>📋 Use-case benchmarks (click to expand)</summary>
|
|
268
|
+
|
|
269
|
+
> **Community-maintained — no verified numbers yet.**
|
|
270
|
+
> If you use llm-zip in a real workload, please submit your results via PR. Include: use case, language, token counts, ratio, preservation score, and model used for savings estimation.
|
|
271
|
+
|
|
272
|
+
| Use case | Tokens in | Tokens out | Ratio | Preservation | Est. saving |
|
|
273
|
+
| :------- | :-------- | :--------- | :---- | :----------- | :---------- |
|
|
274
|
+
| — | — | — | — | — | — |
|
|
275
|
+
|
|
276
|
+
</details>
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Limitations & Caveats
|
|
281
|
+
|
|
282
|
+
- **Language support** — LLMLingua-2 was trained on English meeting transcripts. Spanish and other languages work but may see 10–15% lower compression quality. Community benchmarks are welcome.
|
|
283
|
+
- **Extractive compression** — tokens are removed, not rewritten. Some nuance may be lost at aggressive ratios (above 0.7).
|
|
284
|
+
- **Pricing accuracy** — savings are *estimates*. Non-OpenAI tokenizers use a character-ratio heuristic with a ±10% margin of error.
|
|
285
|
+
- **Format loss** — file conversion extracts plain text only. Layout, tables, and complex formatting are not preserved.
|
|
286
|
+
- **Production testing** — this is v0.1.0. Concurrent batch processing should be monitored closely in high-throughput environments.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Contributing
|
|
291
|
+
|
|
292
|
+
The most valuable contributions right now are benchmark results across different languages, domains, and models. If you use llm-zip in a real project, a PR with your numbers helps everyone calibrate expectations.
|
|
293
|
+
|
|
294
|
+
Bug reports, feature requests, and code contributions are also welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
git clone https://github.com/finktech-dev/llm-zip.git
|
|
298
|
+
cd llm-zip
|
|
299
|
+
pip install -e ".[dev]"
|
|
300
|
+
pytest
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## License & Disclaimer
|
|
306
|
+
|
|
307
|
+
MIT © [FinkTech](https://github.com/finktech-dev)
|
|
308
|
+
|
|
309
|
+
Built utilizing [LLMLingua-2](https://github.com/microsoft/LLMLingua) and [MarkItDown](https://github.com/microsoft/markitdown) open-source libraries.
|
|
310
|
+
|
|
311
|
+
*This project is an independent, community-driven open-source tool. It is not affiliated with, endorsed by, or sponsored by Microsoft Corporation, OpenAI, Anthropic, or any other LLM provider. All trademarks and registered trademarks are the property of their respective owners.*
|
llm_zip-0.1.0/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# 🗜️ llm-zip
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/finktech-dev/llm-zip/releases"><img src="https://img.shields.io/badge/version-0.1.0-blue?style=for-the-badge" alt="Version"></a>
|
|
5
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-22c55e?style=for-the-badge" alt="License"></a>
|
|
6
|
+
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python"></a>
|
|
7
|
+
<a href="https://fastapi.tiangolo.com/"><img src="https://img.shields.io/badge/API-FastAPI-009688?style=for-the-badge&logo=fastapi&logoColor=white" alt="FastAPI"></a>
|
|
8
|
+
<a href="https://www.docker.com/"><img src="https://img.shields.io/badge/Docker-ready-2496ED?style=for-the-badge&logo=docker&logoColor=white" alt="Docker"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/microsoft/LLMLingua"><img src="https://img.shields.io/badge/Powered_by-LLMLingua--2-FF6F00?style=flat-square&logo=microsoft&logoColor=white" alt="LLMLingua-2"></a>
|
|
13
|
+
<a href="https://github.com/microsoft/markitdown"><img src="https://img.shields.io/badge/Files_via-MarkItDown-0078D4?style=flat-square&logo=microsoft&logoColor=white" alt="MarkItDown"></a>
|
|
14
|
+
<a href="https://github.com/BerriAI/litellm"><img src="https://img.shields.io/badge/Pricing-LiteLLM-7C3AED?style=flat-square&logo=github&logoColor=white" alt="LiteLLM"></a>
|
|
15
|
+
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square" alt="Ruff"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<strong>Context compression sidecar for LLM applications.<br>Reduce token costs 3–5× before calling any AI API.</strong>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="#why-llm-zip-exists">Why</a> ·
|
|
24
|
+
<a href="#how-it-works">How it works</a> ·
|
|
25
|
+
<a href="#quickstart">Quickstart</a> ·
|
|
26
|
+
<a href="#the-cli-experience">CLI</a> ·
|
|
27
|
+
<a href="#what-you-get-back">API response</a> ·
|
|
28
|
+
<a href="#markitdown-integration">File support</a> ·
|
|
29
|
+
<a href="#-the-science--benchmarks">Benchmarks</a> ·
|
|
30
|
+
<a href="#limitations--caveats">Limitations</a> ·
|
|
31
|
+
<a href="#contributing">Contributing</a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Why llm-zip exists
|
|
37
|
+
|
|
38
|
+
AI inference is getting expensive. As context windows grow and agentic workflows multiply, the tokens you send to GPT, Claude, or Gemini compound fast — and the "free ride" subsidy era is ending.
|
|
39
|
+
|
|
40
|
+
llm-zip was built out of a simple need: compress context before it reaches the model, without changing anything else in the stack. No proxy. No middleware. No API keys. Just a sidecar you call over HTTP, that hands back a smaller text and tells you exactly how much you saved.
|
|
41
|
+
|
|
42
|
+
It started as an internal tool. It's open source because the problem is universal.
|
|
43
|
+
|
|
44
|
+
> Curious about how this started? Read [STORY.md](STORY.md).
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
Your app ──→ POST /v1/compress ──→ llm-zip
|
|
52
|
+
│
|
|
53
|
+
compresses with LLMLingua-2
|
|
54
|
+
scores semantic preservation
|
|
55
|
+
calculates USD savings
|
|
56
|
+
│
|
|
57
|
+
compressed text + metrics ◄─┘
|
|
58
|
+
|
|
59
|
+
Your app ──→ calls OpenAI / Anthropic / Gemini
|
|
60
|
+
with the smaller context
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
llm-zip never touches your API keys or your model calls. It only compresses.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Quickstart
|
|
68
|
+
|
|
69
|
+
> **Requires Docker.** First-time model download is ~700MB and takes 2–5 min.
|
|
70
|
+
|
|
71
|
+
**Step 1 — Configure**
|
|
72
|
+
|
|
73
|
+
Windows (CMD / PowerShell):
|
|
74
|
+
```powershell
|
|
75
|
+
copy .llmzip.config.example .llmzip.config
|
|
76
|
+
notepad .llmzip.config
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Linux / macOS:
|
|
80
|
+
```bash
|
|
81
|
+
cp .llmzip.config.example .llmzip.config
|
|
82
|
+
nano .llmzip.config
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Step 2 — Download models** *(only on first run)*
|
|
86
|
+
```bash
|
|
87
|
+
docker-compose run llmzip download-models
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Step 3 — Start**
|
|
91
|
+
```bash
|
|
92
|
+
docker-compose up -d
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
→ API: `http://localhost:8000` · Docs: `http://localhost:8000/docs`
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## The CLI Experience
|
|
100
|
+
|
|
101
|
+
llm-zip isn't just an API — it comes with a UNIX-friendly CLI powered by Typer and Rich. It supports `stdin` pipes, outputs clean JSON, and tracks live model prices.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Check current prices (fetches live from LiteLLM)
|
|
105
|
+
$ llmzip prices -p anthropic
|
|
106
|
+
|
|
107
|
+
Rates from LiteLLM as of 2026-06-05
|
|
108
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
|
|
109
|
+
┃ Model ┃ Input $/M ┃ Output $/M ┃
|
|
110
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
|
|
111
|
+
│ anthropic.claude-3-5-sonnet-20241022-v2:0 │ 3.0000 │ 15.0000 │
|
|
112
|
+
│ anthropic.claude-3-haiku-20240307-v1:0 │ 0.2500 │ 1.2500 │
|
|
113
|
+
└───────────────────────────────────────────┴───────────┴────────────┘
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> Model names come directly from LiteLLM and may use provider-specific naming (e.g. Bedrock-style). The exact list depends on live data at execution time.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Compress directly from the terminal via pipes
|
|
120
|
+
$ cat huge_context.txt | llmzip compress --ratio 0.4 --model gpt-4o-mini > compressed.txt
|
|
121
|
+
✓ 24000 → 9600 tokens (2.5×) | score: 0.92 | saved: ~$0.0021 (gpt-4o-mini)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## What you get back
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"compressed": "...",
|
|
131
|
+
"original_tokens": 8400,
|
|
132
|
+
"compressed_tokens": 1680,
|
|
133
|
+
"compression_ratio": 5.0,
|
|
134
|
+
"preservation_score": 0.91,
|
|
135
|
+
"estimated_savings": {
|
|
136
|
+
"gpt-4o-mini": "$0.0010",
|
|
137
|
+
"claude-haiku-4-5": "$0.0013",
|
|
138
|
+
"gemini-2.5-flash-lite": "$0.0006"
|
|
139
|
+
},
|
|
140
|
+
"skipped": false,
|
|
141
|
+
"warning": null
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Prices are fetched live from [LiteLLM](https://github.com/BerriAI/litellm) with local caching — no manual database updates needed.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## MarkItDown Integration
|
|
150
|
+
|
|
151
|
+
One of the practical problems that motivated llm-zip was RAG over internal documents. In private systems — invoices, reports, manuals, internal specs — the source content lives in PDFs, Word files, and spreadsheets.
|
|
152
|
+
|
|
153
|
+
llm-zip integrates [MarkItDown](https://github.com/microsoft/markitdown) as an optional preprocessing layer. When `FILE_CONVERSION=true`, you can send a file directly to `/v1/compress/file` and get back compressed text ready for your RAG pipeline.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
curl -X POST http://localhost:8000/v1/compress/file \
|
|
157
|
+
-F "file=@invoice.pdf" \
|
|
158
|
+
-F "ratio=0.5"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Supported formats: PDF, Word (`.docx`), Excel (`.xlsx`), PowerPoint (`.pptx`), and more.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Key Features
|
|
166
|
+
|
|
167
|
+
| | Feature | Detail |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| 📄 | **Text and files** | Compress plain text or upload PDFs, Word, Excel, and PowerPoint directly |
|
|
170
|
+
| 🖥️ | **CPU-Friendly** | Default model requires only ~700MB of RAM — no GPU needed |
|
|
171
|
+
| 🌐 | **Global i18n** | CLI in English, Spanish, Portuguese, Chinese, and Japanese |
|
|
172
|
+
| ⚙️ | **Configurable thresholds** | Define when llm-zip should and shouldn't intervene (`MIN_TOKENS_TO_COMPRESS`) |
|
|
173
|
+
| 🚫 | **Ignore rules** | Exclude texts or system prompts via `.llmzipignore` and `.llmzipignore.local` |
|
|
174
|
+
| 🔒 | **Self-hosted** | Your data never leaves your infrastructure |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Environment Variables
|
|
179
|
+
|
|
180
|
+
For CI or Docker deployments, you can override defaults with environment variables:
|
|
181
|
+
|
|
182
|
+
| Variable | Description |
|
|
183
|
+
|---|---|
|
|
184
|
+
| `LLMZIP_LANG` | Forces CLI language (`en`, `es`, `pt`, `zh`, `ja`). Overrides system locale. |
|
|
185
|
+
| `MODELS_URL` | Overrides internal DNS for the models container. Defaults to `http://llmzip-models:8001`. |
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 📊 The Science & Benchmarks
|
|
190
|
+
|
|
191
|
+
llm-zip is powered by Microsoft's LLMLingua-2. According to their [research paper evaluated on the LongBench dataset](https://arxiv.org/abs/2403.12968):
|
|
192
|
+
|
|
193
|
+
- **Compression sweet spot:** optimal performance between **2× and 5× compression**
|
|
194
|
+
- **Quality retention:** **90–98% Exact Match performance** vs. uncompressed prompts
|
|
195
|
+
- **Latency reduction:** end-to-end latency improvement of **1.6× to 2.9×** (task-agnostic, no prompt needed to start)
|
|
196
|
+
|
|
197
|
+
<details>
|
|
198
|
+
<summary>📋 Hardware benchmarks (click to expand)</summary>
|
|
199
|
+
|
|
200
|
+
> **Community-maintained — no verified numbers yet.**
|
|
201
|
+
> If you run llm-zip on real hardware, please submit your results via PR. Include: hardware, model (`bert-base` or `xlm-roberta-large`), input token count, and time to compress.
|
|
202
|
+
|
|
203
|
+
| Hardware | Model | Input Tokens | Time to Compress |
|
|
204
|
+
| :------- | :---- | :----------- | :--------------- |
|
|
205
|
+
| — | — | — | — |
|
|
206
|
+
|
|
207
|
+
</details>
|
|
208
|
+
|
|
209
|
+
<details>
|
|
210
|
+
<summary>📋 Use-case benchmarks (click to expand)</summary>
|
|
211
|
+
|
|
212
|
+
> **Community-maintained — no verified numbers yet.**
|
|
213
|
+
> If you use llm-zip in a real workload, please submit your results via PR. Include: use case, language, token counts, ratio, preservation score, and model used for savings estimation.
|
|
214
|
+
|
|
215
|
+
| Use case | Tokens in | Tokens out | Ratio | Preservation | Est. saving |
|
|
216
|
+
| :------- | :-------- | :--------- | :---- | :----------- | :---------- |
|
|
217
|
+
| — | — | — | — | — | — |
|
|
218
|
+
|
|
219
|
+
</details>
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Limitations & Caveats
|
|
224
|
+
|
|
225
|
+
- **Language support** — LLMLingua-2 was trained on English meeting transcripts. Spanish and other languages work but may see 10–15% lower compression quality. Community benchmarks are welcome.
|
|
226
|
+
- **Extractive compression** — tokens are removed, not rewritten. Some nuance may be lost at aggressive ratios (above 0.7).
|
|
227
|
+
- **Pricing accuracy** — savings are *estimates*. Non-OpenAI tokenizers use a character-ratio heuristic with a ±10% margin of error.
|
|
228
|
+
- **Format loss** — file conversion extracts plain text only. Layout, tables, and complex formatting are not preserved.
|
|
229
|
+
- **Production testing** — this is v0.1.0. Concurrent batch processing should be monitored closely in high-throughput environments.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
|
|
235
|
+
The most valuable contributions right now are benchmark results across different languages, domains, and models. If you use llm-zip in a real project, a PR with your numbers helps everyone calibrate expectations.
|
|
236
|
+
|
|
237
|
+
Bug reports, feature requests, and code contributions are also welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
git clone https://github.com/finktech-dev/llm-zip.git
|
|
241
|
+
cd llm-zip
|
|
242
|
+
pip install -e ".[dev]"
|
|
243
|
+
pytest
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## License & Disclaimer
|
|
249
|
+
|
|
250
|
+
MIT © [FinkTech](https://github.com/finktech-dev)
|
|
251
|
+
|
|
252
|
+
Built utilizing [LLMLingua-2](https://github.com/microsoft/LLMLingua) and [MarkItDown](https://github.com/microsoft/markitdown) open-source libraries.
|
|
253
|
+
|
|
254
|
+
*This project is an independent, community-driven open-source tool. It is not affiliated with, endorsed by, or sponsored by Microsoft Corporation, OpenAI, Anthropic, or any other LLM provider. All trademarks and registered trademarks are the property of their respective owners.*
|