A sophisticated React application that implements advanced rule-based techniques for optimizing AI prompts without requiring external APIs. This tool uses natural language processing to intelligently compress and improve prompts while maintaining their core meaning.
- Identifies and removes verbose phrases like "Could you please provide me with..."
- Converts indirect requests to direct instructions
- Eliminates filler words and politeness indicators
- Uses Compromise.js for natural language processing
- Removes low-information words based on strategy (conservative/balanced/aggressive)
- Identifies and removes adverbs, intensifiers, and filler words
- Strategy-based word filtering
- Detects passive voice constructions
- Converts to active voice for clarity and conciseness
- Examples: "It is requested that..." → "Do..."
- Replaces long phrases with shorter equivalents
- Uses synonym mapping for common verbose expressions
- Examples: "in order to" → "to", "provide a comprehensive explanation" → "explain thoroughly"
- Converts multiple requests into structured formats
- Uses bullet points and semicolons for clarity
- Transforms questions into direct instructions
- Extracts essential nouns, verbs, and proper nouns
- Filters out common words and stop-words
- Creates minimal keyword-based prompts
- Maintains action context (Explain, Summarize, Analyze, etc.)
- React 18 - Modern React with hooks
- Compromise.js - Lightweight NLP library for browser
- CSS3 - Modern styling with responsive design
// Main optimization function
optimizePrompt(prompt, strategy)
// Individual optimization techniques
removePolitePhrasing(text, optimizations)
removeStopWords(text, strategy, optimizations)
convertPassiveToActive(text, optimizations)
shortenExpressions(text, optimizations)
applyStructuredFormat(text, optimizations)
extractKeywords(text, optimizations)- Conservative: Minimal changes, removes only basic politeness
- Balanced: Moderate optimization, removes common filler words
- Aggressive: Maximum compression, includes keyword extraction
The optimizer provides comprehensive metrics:
- Token Count: Before/after token estimation
- Quality Score: Algorithmic quality assessment (0.7-0.99)
- Carbon Savings: Environmental impact calculation
- Optimization Log: Detailed list of applied changes
"Could you please provide me with a comprehensive summary of the economic impacts of climate change on developing countries along with key themes and main factors?"
"Provide summary of economic impacts of climate change on developing countries along with key themes and main factors"
"Summarize economic impacts of climate change on developing countries; key themes; main factors"
"Summarize: climate change; economic impacts; developing countries; key themes; main factors"
-
Install dependencies:
npm install
-
Start development server:
npm start
-
Open browser: Navigate to
http://localhost:3000
src/
├── components/
│ ├── PromptOptimizer.js # Main React component
│ └── PromptOptimizer.css # Component styles
├── utils/
│ ├── promptOptimizer.js # Core optimization logic
│ └── testOptimizer.js # Test cases and examples
├── App.js # Main app component
└── App.css # Global styles
Extend the pattern libraries in promptOptimizer.js:
const politePatterns = [
{
pattern: /your-regex-pattern/gi,
replacement: 'replacement',
description: 'Description of optimization'
}
];Modify the stopWords object to add domain-specific terms:
const stopWords = {
conservative: ['your', 'custom', 'words'],
balanced: ['more', 'words'],
aggressive: ['even', 'more', 'words']
};Run the test suite to see optimization examples:
import { testOptimizer } from './src/utils/testOptimizer.js';
// Run in browser console or Node.js- No External APIs: Completely offline and private
- Fast Processing: Rule-based approach is extremely fast
- Deterministic: Same input always produces same output
- Customizable: Easy to modify patterns and strategies
- Comprehensive: Multiple optimization techniques in one tool
- Metrics: Detailed analytics and quality scoring
- Machine learning-based pattern recognition
- Domain-specific optimization rules
- Advanced grammar analysis
- Multi-language support
- API integration for cloud processing
This project is open source and available under the MIT License.
Built with ❤️ using React and Compromise.js