Toolkit-for-Prompt-Compression: A Unified Toolkit for LLM Prompt Compression
This repository profile is provided by osrepos.com, an open source repository discovery platform.
Summary
PCToolkit is a unified, plug-and-play toolkit designed for efficient prompt compression in Large Language Models (LLMs). It provides state-of-the-art compression methods, diverse datasets, and comprehensive metrics for evaluating performance. This modular toolkit simplifies the process of condensing input prompts while preserving crucial information.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
PCToolkit is a unified, plug-and-play prompt compression toolkit for Large Language Models (LLMs). Prompt compression is an innovative method for efficiently condensing input prompts while preserving essential information, crucial for optimizing LLM inference efficiency. This toolkit offers a comprehensive solution, featuring cutting-edge prompt compressors, diverse datasets, and metrics for thorough performance evaluation.
Key features of PCToolkit include:
- State-of-the-art and reproducible methods: It encompasses five distinct mainstream compression techniques: Selective Context, LLMLingua, LongLLMLingua, SCRL, and Keep it Simple.
- User-friendly interfaces: Designed for portability and easy adaptation, allowing for simple integration of new compressors, datasets, and metrics.
- Modular design: Organized into Compressor, Dataset, Metric, and Runner modules, simplifying transitions between different methods and evaluation components.
PCToolkit includes 5 compression methods, 11 datasets, and over 5 metrics, evaluated across various natural language tasks like reconstruction, summarization, mathematical problem-solving, and question answering.
Installation
To get started with PCToolkit, follow these steps:
First, clone the repository:
git clone https://github.com/3DAgentWorld/Toolkit-for-Prompt-Compression.git
Navigate into the cloned directory:
cd Toolkit-for-Prompt-Compression
Then, install the required dependencies:
pip install -r requirements.txt
Please note that while most models can be automatically downloaded from Huggingface Hub, models for the SCRL method require manual download. Refer to the guidance within the /models folder for detailed instructions.
Examples
PCToolkit provides straightforward interfaces for both prompt compression and evaluation.
Prompt Compression
To perform prompt compression, you can use the PromptCompressor class:
from pctoolkit.compressors import PromptCompressor
compressor = PromptCompressor(type='SCCompressor', device='cuda')
test_prompt = "test prompt"
ratio = 0.3
result = compressor.compressgo(test_prompt, ratio)
print(result)
Evaluation
For evaluating compressor performance, follow this example:
from pctoolkit.runners import run
from pctoolkit.datasets import load_dataset
from pctoolkit.metrics import load_metrics
from pctoolkit.compressors import PromptCompressor
compressor = PromptCompressor(type='SCCompressor', device='cuda')
dataset_name = 'arxiv'
dataset = load_dataset(dataset_name)
run(compressor=compressor, dataset=dataset, metrics=load_metrics, ratio=0.1)
Hint: Remember to fill in your Huggingface Tokens and API keys for OpenAI in pctoolkit/runners.py. You can also modify the URLs if you are using other OpenAI APIs. If you wish to change the metrics, specifically for the LongBench dataset, modify pctoolkit/metrics.py.
Why Use PCToolkit?
PCToolkit offers a robust and versatile solution for anyone working with Large Language Models and seeking to optimize prompt efficiency. Its key advantages include:
- Comprehensive Coverage: Integrates five state-of-the-art prompt compression methods, providing a wide range of options for different use cases.
- Ease of Use: Features user-friendly interfaces that simplify the process of applying compression techniques and evaluating their impact.
- Modularity and Extensibility: Its modular design allows for easy integration of new datasets, metrics, and even custom compression methods, making it highly adaptable.
- Extensive Evaluation: Comes with support for 11 diverse datasets and over 5 metrics, enabling thorough and reproducible evaluation across various NLP tasks.
- Research and Development Ready: Ideal for researchers and developers looking to experiment with, compare, and build upon existing prompt compression techniques.
Links
- GitHub Repository: https://github.com/3DAgentWorld/Toolkit-for-Prompt-Compression
- Technical Report (Paper): https://arxiv.org/abs/2403.17411
- Hugging Face Demo: https://huggingface.co/spaces/CjangCjengh/Prompt-Compression-Toolbox
Related repositories
Similar repositories that may be relevant next.

DA-Forge: Streamlining Declarative Agent Creation for Copilot Notebooks
September 12, 2026
DA-Forge is a Python-based tool by Microsoft designed to automate the creation and deployment of Declarative Agents for Copilot Notebooks. It significantly reduces the manual effort and time required to set up AI assistants with specific grounding references, transforming an 85-minute process into just a few minutes. This tool is essential for developers and researchers working with Copilot Notebooks and Declarative Agents.

Curie: Automated and Rigorous Scientific Experimentation with AI Agents
September 12, 2026
Curie is an innovative AI-agent framework designed for automating rigorous scientific experimentation. It streamlines the entire research lifecycle, from hypothesis formulation to result interpretation, ensuring precision, reliability, and reproducibility. This empowers scientists to accelerate their research processes significantly.

Tau: A Minimalist Python Coding Agent for Your Terminal
September 8, 2026
Tau is a Python port of Pi's minimalist coding agent, designed to live in your terminal. It allows users to make requests like "explain this repo" or "add tests," and it can read files, edit code, and run commands. Beyond its utility, Tau also serves as a teaching project, demonstrating how coding agents are built with a small, readable codebase.

Awesome Harness Engineering: Building Reliable AI Agent Systems
September 7, 2026
Awesome Harness Engineering is a comprehensive curated list dedicated to the discipline of designing robust AI agent harnesses. It offers a wealth of resources, patterns, and templates essential for building reliable AI agent systems. Developers can explore tools, best practices, and foundational concepts across various critical areas of agent development.
Source repository
Open the original repository on GitHub.
14 counted GitHub visits