Built a system that reduces AI energy consumption by selecting the most efficient LLM for a task and compressing prompts to lower token usage, helping minimize carbon emissions and inference costs while maintaining response quality.
See the codeThis project is an LLM optimization and evaluation system designed to reduce the carbon footprint and computational cost of Large Language Model (LLM) inference. It accomplishes this through intelligent prompt compression and dynamic model routing based on prompt complexity, while tracking the energy consumption and carbon emissions of the generation process.
LLMLingua to effectively compress input prompts, reducing the number of tokens without losing the semantic meaning or intent.Nvidia NeMo Curator and intelligently routes the prompt to the most suitable LLM (e.g., Gemini 1.5 Flash 8B for low complexity, Gemini 1.5 Pro for high complexity) to optimize resource usage.EcoLogits to track and estimate the energy consumption (kWh) and carbon footprint (kg CO2eq) for each request, allowing for direct comparison between the original and compressed prompt requests.llama-3.3-70b-versatile) to evaluate and compare the quality of the responses generated from the original and compressed prompts, ensuring that quality is maintained while saving resources.FastAPI powered backend exposing the /evaluate endpoint for seamless integration.server.py: The main FastAPI server exposing the evaluation endpoint.compress_prompt.py: Core logic for prompt compression using LLMLingua-2 and EcoLogits.llm_router.py: Handles analyzing prompt complexity and routing to the optimal LLM.Nvidia prompt class/: Contains scripts and logic for utilizing NeMo Curator for prompt complexity analysis.frontend/: The React (Vite) frontend application.Clone the repository and navigate to the project directory:
cd Carbon-Footprint-Aware-System-for-Optimal-LLM-Selection-and-Prompt-Compression
Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
Install the required Python packages:
pip install -r requirements.txt
Configure Environment Variables: Copy the example environment file and fill in your API keys.
cp .env.example .env
Open .env and add:
GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_here
Navigate to the frontend directory:
cd frontend
Install the Node.js dependencies:
npm install
Configure Frontend Environment Variables:
Copy .env.example to .env inside the frontend folder.
cp .env.example .env
Set the API URL for the backend (usually http://localhost:8000 for local development):
VITE_API_URL=http://localhost:8000
Start the Backend Server: From the root project directory:
python server.py
The backend will start at http://0.0.0.0:8000.
Start the Frontend Development Server:
From the frontend/ directory:
npm run dev
The UI will be accessible typically at http://localhost:5173.
The backend provides a main endpoint:
POST /evaluate: Accepts a JSON payload {"prompt": "Your text here"}. Returns a comprehensive evaluation comparing the original prompt's response against the optimized, compressed route, including token counts, savings, and an AI judge's rating.For detailed instructions on deploying the backend (Docker + Render) and frontend (Vercel), please refer to the DEPLOYMENT.md guide.
The system logs compression ratios, origin/compressed token counts, and carbon emission stats to compression_logs.txt locally for analysis.
Built a system that reduces AI energy consumption by selecting the most efficient LLM for a task and compressing prompts to lower token usage, helping minimize carbon emissions and inference costs while maintaining response quality.
See the codeThis project is an LLM optimization and evaluation system designed to reduce the carbon footprint and computational cost of Large Language Model (LLM) inference. It accomplishes this through intelligent prompt compression and dynamic model routing based on prompt complexity, while tracking the energy consumption and carbon emissions of the generation process.
LLMLingua to effectively compress input prompts, reducing the number of tokens without losing the semantic meaning or intent.Nvidia NeMo Curator and intelligently routes the prompt to the most suitable LLM (e.g., Gemini 1.5 Flash 8B for low complexity, Gemini 1.5 Pro for high complexity) to optimize resource usage.EcoLogits to track and estimate the energy consumption (kWh) and carbon footprint (kg CO2eq) for each request, allowing for direct comparison between the original and compressed prompt requests.llama-3.3-70b-versatile) to evaluate and compare the quality of the responses generated from the original and compressed prompts, ensuring that quality is maintained while saving resources.FastAPI powered backend exposing the /evaluate endpoint for seamless integration.server.py: The main FastAPI server exposing the evaluation endpoint.compress_prompt.py: Core logic for prompt compression using LLMLingua-2 and EcoLogits.llm_router.py: Handles analyzing prompt complexity and routing to the optimal LLM.Nvidia prompt class/: Contains scripts and logic for utilizing NeMo Curator for prompt complexity analysis.frontend/: The React (Vite) frontend application.Clone the repository and navigate to the project directory:
cd Carbon-Footprint-Aware-System-for-Optimal-LLM-Selection-and-Prompt-Compression
Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
Install the required Python packages:
pip install -r requirements.txt
Configure Environment Variables: Copy the example environment file and fill in your API keys.
cp .env.example .env
Open .env and add:
GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_here
Navigate to the frontend directory:
cd frontend
Install the Node.js dependencies:
npm install
Configure Frontend Environment Variables:
Copy .env.example to .env inside the frontend folder.
cp .env.example .env
Set the API URL for the backend (usually http://localhost:8000 for local development):
VITE_API_URL=http://localhost:8000
Start the Backend Server: From the root project directory:
python server.py
The backend will start at http://0.0.0.0:8000.
Start the Frontend Development Server:
From the frontend/ directory:
npm run dev
The UI will be accessible typically at http://localhost:5173.
The backend provides a main endpoint:
POST /evaluate: Accepts a JSON payload {"prompt": "Your text here"}. Returns a comprehensive evaluation comparing the original prompt's response against the optimized, compressed route, including token counts, savings, and an AI judge's rating.For detailed instructions on deploying the backend (Docker + Render) and frontend (Vercel), please refer to the DEPLOYMENT.md guide.
The system logs compression ratios, origin/compressed token counts, and carbon emission stats to compression_logs.txt locally for analysis.