A lightweight tool that leverages open-source LLMs to automatically generate documentation and unit tests for Python code, complete with evaluation metrics.
This tool demonstrates key competencies in:
- LLM Application Development: Integration with open-source models
- Prompt Engineering: Optimized prompts for code analysis
- Evaluation Metrics: Quantitative assessment of LLM outputs
- Workflow Automation: End-to-end code analysis pipeline
-
Automatic Documentation Generation
- Docstrings for functions and classes
- Module-level documentation
- Inline comments for complex logic
-
Unit Test Generation
- Pytest-compatible test cases
- Edge case detection
- Coverage-focused test generation
-
Evaluation Metrics
- Token efficiency analysis
- Response time tracking
- Quality scoring (completeness, correctness)
- Comparative model performance
- Python 3.8+
- Ollama installed locally (for open-source LLMs)
# macOS/Linux
curl -fsSL https://ollama.com/install.sh | sh
# Or visit: https://ollama.com/downloadollama pull llama3.2 # Clone or navigate to project directory
cd CodeDoc
# Install dependencies
pip install -r requirements.txt# Generate documentation for a Python file
python codedoc.py --file examples/sample.py --mode doc
# Generate unit tests
python codedoc.py --file examples/sample.py --mode test
# Generate both documentation and tests
python codedoc.py --file examples/sample.py --mode all
# Run with evaluation metrics
python codedoc.py --file examples/sample.py --mode all --evaluate# Specify a different model
python codedoc.py --file mycode.py --mode all --model codellama
# Compare multiple models
python codedoc.py --file mycode.py --mode all --compare-models llama3.2,mistral
# Output to specific directory
python codedoc.py --file mycode.py --mode all --output ./generatedThe tool tracks:
-
Performance Metrics
- Response time per request
- Tokens per second
- Total tokens used
-
Quality Metrics
- Documentation completeness score
- Test coverage estimation
- Syntax validity
-
Comparative Analysis
- Side-by-side model comparison
- Cost-benefit analysis
- Speed vs. quality trade-offs
CodeDoc/
├── codedoc.py # Main application
├── llm_handler.py # LLM integration layer
├── doc_generator.py # Documentation generation
├── test_generator.py # Unit test generation
├── evaluator.py # Evaluation metrics
├── config.py # Configuration settings
├── requirements.txt # Dependencies
├── examples/ # Sample Python files
│ ├── sample.py
│ └── calculator.py
└── output/ # Generated files (created at runtime)
-
LLM Optimization
- Iterative prompt refinement
- Context window management
- Temperature and parameter tuning
-
Evaluation Framework
- Quantitative metrics design
- Benchmarking methodology
- Performance tracking
-
Workflow Automation
- Code parsing and analysis
- Batch processing
- Error handling and retry logic
-
Scalability Considerations
- Rate limiting
- Caching strategies
- Parallel processing opportunities
See examples/ directory for sample inputs and output/ for generated documentation and tests.
This is a portfolio project designed to demonstrate LLM application development capabilities.
MIT License - Free to use and modify