Tips and Tricks
This page provides advanced tips, tricks, and best practices to help you get the most out of promptprep.
Optimizing for AI Models
When preparing code for AI models like GPT-4:
Use Markdown Format
Markdown format works best with AI models as it preserves syntax highlighting:
promptprep --format markdown -c
Monitor Token Usage
Stay within context limits by monitoring token usage:
promptprep --metadata --count-tokens --format markdown -c
Focus on Relevant Files
Only include files that are relevant to your question:
promptprep -i "src/problematic_file.py,src/related_file.py" -c
Use Summary Mode for Large Codebases
For large projects, use summary mode to extract only signatures and docstrings:
promptprep --summary-mode --format markdown -c
Strip Comments When Needed
If you’re approaching token limits, consider stripping comments:
promptprep --no-include-comments --format markdown -c
Performance Optimization
For large codebases:
Use Incremental Processing
Only process files that have changed:
promptprep --incremental -o updated_output.txt
Filter by Extension
Focus on specific file types:
promptprep -x ".py,.js" -o filtered_output.txt
Exclude Large Directories
Skip directories that contain many files:
promptprep -e "node_modules,venv,build,dist" -o smaller_output.txt
Limit File Size
Reduce the maximum file size to skip large files:
promptprep -m 1 -o no_large_files.txt # Skip files larger than 1MB
Combine Filtering Techniques
Use multiple filters together:
promptprep -x ".py" -e "tests,venv" -m 1 -o optimized.txt
Workflow Integration
Integrate promptprep into your development workflow:
Git Hooks
Create a pre-commit hook to generate code snapshots:
# In .git/hooks/pre-commit #!/bin/bash promptprep -d . --incremental -o snapshots/$(date +%Y%m%d_%H%M%S).md
Alias Commands
Create shell aliases for common operations:
# In .bashrc or .zshrc alias pp-ai="promptprep --format markdown --metadata --count-tokens -c" alias pp-docs="promptprep --format highlighted -o docs/code_snapshot.html"
Continuous Integration
Add promptprep to your CI pipeline:
# In .github/workflows/snapshot.yml jobs: snapshot: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: '3.10' - run: pip install promptprep - run: promptprep -d . --metadata -o snapshot.md
Documentation Generation
Automatically update documentation:
# In your documentation build script promptprep -d ./src --summary-mode --format markdown -o docs/api_overview.md
Diff Reports
Generate diff reports between branches:
# Save main branch snapshot git checkout main promptprep -d . -o main_snapshot.txt # Compare feature branch git checkout feature-branch promptprep -d . --diff main_snapshot.txt -o changes.txt
Advanced Selection Techniques
Fine-tune which files are included:
Combine Interactive and Extension Filtering
Pre-filter by extension, then select interactively:
promptprep -x ".py,.js" --interactive -o selected.txt
Use Glob Patterns with Include Files
Use shell expansion for file patterns:
promptprep -i "$(find src -name "*.py" | tr '\n' ',')" -o python_files.txt
Exclude by Pattern
Exclude files matching certain patterns:
promptprep -e "$(find . -name "*_test.py" -o -name "test_*.py" | xargs dirname | sort -u | tr '\n' ',')" -o no_tests.txt
Select by Modification Time
Focus on recently modified files:
promptprep -i "$(find . -type f -mtime -7 | tr '\n' ',')" -o recent_changes.txt
Combine with grep
Select files containing specific text:
promptprep -i "$(grep -l "TODO" --include="*.py" -r . | tr '\n' ',')" -o todos.txt
Custom Output Strategies
Customize your output for different purposes:
Create Custom Templates for Different Audiences
Maintain different templates for different needs:
promptprep --format custom --template-file templates/for_ai.txt -o for_ai.txt promptprep --format custom --template-file templates/for_docs.txt -o for_docs.txt
Generate Multiple Formats at Once
Create a script to generate multiple formats:
#!/bin/bash promptprep -d . -o output.txt promptprep -d . --format markdown -o output.md promptprep -d . --format highlighted -o output.html
Create Focused Reports
Generate reports for specific components:
for dir in src/*/ ; do promptprep -d "$dir" --metadata -o "reports/$(basename $dir).md" done
Combine with Other Tools
Pipe output to other tools:
promptprep -c | pbcopy # macOS promptprep -c | xclip -selection clipboard # Linux
Create Comparative Views
Generate side-by-side comparisons:
# Generate HTML with both the full code and summary promptprep -d . --format html -o full.html promptprep -d . --summary-mode --format html -o summary.html echo "<frameset cols=\"50%,50%\"><frame src=\"full.html\"><frame src=\"summary.html\"></frameset>" > comparison.html
Troubleshooting Common Issues
Solutions to common problems:
Files Not Being Included
Check file paths and patterns:
# List all files that would be included find . -type f -not -path "*/\.*" | grep -v -E "(__pycache__|node_modules|venv)"
Output Too Large
Reduce output size:
# Use summary mode promptprep --summary-mode -o smaller.txt # Exclude comments promptprep --no-include-comments -o no_comments.txt # Focus on specific directories promptprep -d ./src/core -o core_only.txt
Slow Performance
Improve performance:
# Use incremental processing promptprep --incremental -o faster.txt # Exclude large directories promptprep -e "node_modules,venv,data,logs" -o faster.txt
Encoding Issues
Handle non-standard encodings:
# Convert files to UTF-8 first find . -type f -name "*.py" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o {}.utf8 \; find . -type f -name "*.py.utf8" -exec mv {} {} \;
Line Ending Issues
Normalize line endings:
# Convert to Unix line endings find . -type f -name "*.py" -exec dos2unix {} \;
Advanced Configuration Management
Master configuration management:
Project-Specific Configurations
Create configurations for different projects:
# For frontend code promptprep -d ./frontend -x ".js,.ts,.jsx,.tsx" --save-config frontend.json # For backend code promptprep -d ./backend -x ".py,.sql" --save-config backend.json
Layered Configurations
Combine multiple configurations:
# Base configuration promptprep --load-config base.json --format markdown -o output.md
Environment-Specific Configurations
Use different configurations based on environment:
# In your script if [ "$ENV" = "dev" ]; then CONFIG="dev.json" else CONFIG="prod.json" fi promptprep --load-config $CONFIG -o output.txt
Share Configurations with Team
Include configurations in version control:
# In README.md ## Team Configurations We maintain standard configurations in the `.promptprep` directory. Use them with: ```bash promptprep --load-config .promptprep/standard.json ```
Document Your Configurations
Add comments to your configuration files:
{ "_comment": "Configuration for backend code review", "directory": "./backend", "extensions": [".py", ".sql"], "exclude_dirs": ["tests", "migrations"], "format": "highlighted", "line_numbers": true }