AI Prompt Slimming Toolkit — reduce token consumption at the source before every API call. 40+ Chinese & English redundancy patterns, code protection, Anthropic Prompt Caching analysis.
Project description
PromptSlim 🪒
AI Prompt Slimming Toolkit — reduce token consumption at the source before every API call.
🎯 Token Optimization · Cost Saving · Prompt Engineering · LLM Tools
📖 掘金详解 v0.3.0: 给你的 AI 提示词剃得再干净一点
What Problem Does This Solve?
Every word you send to an LLM costs money. Filler words, redundant phrases, and polite fluff silently drain your budget. Most developers don't realize 5-40% of their token spend is waste.
PromptSlim strips redundancy at the prompt level — before it reaches the API — giving you free savings with zero code changes to your app logic.
Quick Start
pip install git+https://github.com/JING04-PRODUCER/promptslim.git
Python SDK
from promptslim import quick_slim
text = "嗯,那个我想说的是,这个功能非常非常好用,对吧?"
report = quick_slim(text)
print(f"Token saved: {report.savings_pct}% | Cost saved: ${report.cost_per_call_saved:.6f}/call")
CLI
# Count tokens
promptslim count "Hello world" -m gpt-4o
# Quick slim (rule-based, no API required)
promptslim slim prompt.txt -o slimmed.txt
# Smart compression (LLM-powered, preserves semantics)
promptslim smart long_chat.json -m gpt-4o-mini --max-tokens 512 -o slimmed.txt
# Compare two texts
promptslim compare old.txt new.txt
Demo
Original: In order to basically say that this is really very important
and actually I think we should definitely consider it.
Slimmed: say this is important and I think we should consider it.
Saved: 31.3% tokens
Original: 嗯,那个我想说的是,这个功能非常非常非常好用,对吧?你知道吗?
Slimmed: 我想说的是,这个功能好用。
Saved: 40.0% tokens
Features
| Feature | Description |
|---|---|
| 🔍 Redundancy Detection | 40+ patterns in Chinese & English — filler words, redundant modifiers, verbose phrases |
| 📝 Smart Compression | LLM-powered semantic compression for chat history before context overflow |
| 📊 Comparison Reports | Before/after token count, cost, and savings percentage at a glance |
| 🎯 Multi-Model Tokenizer | Accurate tiktoken counting for GPT / Claude / DeepSeek / Qwen |
| 🔧 Python SDK | One-line integration: from promptslim import quick_slim |
| 🌐 Bilingual | Works with both Chinese and English text |
Redundancy Patterns
| Type | Examples |
|---|---|
| English fillers | um, uh, hmm, basically, literally, actually |
| English modifiers | very, really, extremely, absolutely |
| English verbose phrases | in order to → to, due to the fact that → because |
| Chinese fillers | 嗯, 啊, 哦, 那个, 就是说 |
| Chinese modifiers | 非常, 特别, 极其, 十分, 超级 |
| Polite fluff | 希望对你有所帮助, 如有问题请随时联系 |
| Repeated punctuation | !!→!, ??→? |
Paired with AI Cost Sentinel
Slim before call → Track after call. Form a complete cost optimization loop.
import openai
from promptslim import quick_slim
# 1. Slim before sending
text = load_prompt()
report = quick_slim(text)
# 2. Send through Sentinel proxy (tracks actual cost)
client = openai.OpenAI(base_url="http://localhost:8000/v1")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": report.slimmed}]
)
# 3. See estimated savings
print(f"Estimated savings: ${report.cost_per_call_saved:.6f}/call")
Project Structure
promptslim/
├── promptslim/
│ ├── __init__.py # Public API exports
│ ├── cli.py # CLI entry point
│ ├── compressor.py # Compressors (rule-based + LLM)
│ ├── redundancy.py # Redundancy detection patterns
│ ├── reporter.py # Report generation + pricing table
│ └── tokenizer.py # Multi-model token counting
├── tests/
│ └── test_prompslim.py
├── pyproject.toml
└── README.md
Roadmap
- Web playground (paste text, see savings live)
- VS Code extension (slim on save)
- Custom regex rules
- Batch processing directory
- LangChain / LlamaIndex integration
AI Assistance
This project was developed with Claude (Anthropic) as a coding assistant. AI contributions include code structure suggestions, test generation, and documentation drafts. All AI-generated code has been reviewed and verified by the developer. Design decisions and core logic are independently authored.
License
MIT — see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptslim-0.3.0.tar.gz.
File metadata
- Download URL: promptslim-0.3.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78888f55e4b9cfd2984f57f8d423a28e884315876db167b938df2635c1c229c0
|
|
| MD5 |
c3b3f727afb7d3da8e96f4000a40e51d
|
|
| BLAKE2b-256 |
6fce1b0c2e108571187ec94a7776476f9f3d204edfd35fc6bd58e33de2f9fe08
|
Provenance
The following attestation bundles were made for promptslim-0.3.0.tar.gz:
Publisher:
publish.yml on JING04-PRODUCER/promptslim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptslim-0.3.0.tar.gz -
Subject digest:
78888f55e4b9cfd2984f57f8d423a28e884315876db167b938df2635c1c229c0 - Sigstore transparency entry: 1858289795
- Sigstore integration time:
-
Permalink:
JING04-PRODUCER/promptslim@f605f4b00462d90b27a977b5913d333f3fed457a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/JING04-PRODUCER
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f605f4b00462d90b27a977b5913d333f3fed457a -
Trigger Event:
push
-
Statement type:
File details
Details for the file promptslim-0.3.0-py3-none-any.whl.
File metadata
- Download URL: promptslim-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e2fcdac448f915d968e84bb523bc09c41e49b67c0f7eaa2c1fdf50d57890a9c
|
|
| MD5 |
b90574f77e27d3bb65c4b1c0707ce8f0
|
|
| BLAKE2b-256 |
d87da51a590500aae340def1fab7ab1b199d9630c73e77c5ced35aa7c5c72dfd
|
Provenance
The following attestation bundles were made for promptslim-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on JING04-PRODUCER/promptslim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptslim-0.3.0-py3-none-any.whl -
Subject digest:
2e2fcdac448f915d968e84bb523bc09c41e49b67c0f7eaa2c1fdf50d57890a9c - Sigstore transparency entry: 1858289805
- Sigstore integration time:
-
Permalink:
JING04-PRODUCER/promptslim@f605f4b00462d90b27a977b5913d333f3fed457a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/JING04-PRODUCER
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f605f4b00462d90b27a977b5913d333f3fed457a -
Trigger Event:
push
-
Statement type: