A standalone code review system using Qwen2.5-0.5B to review AI-generated code against the Universal Code Criticality Protocol (UCCP).
✅ Free - Uses local Qwen2.5-0.5B via Ollama (no API costs)
✅ Fast - Reviews code in 50-200ms
✅ Standalone - Self-contained package
✅ UCCP Compliant - Reviews against Universal Code Criticality Protocol
✅ Non-Intrusive - Reviews code, doesn't edit (provides feedback)
AI generates code → Qwen reviews it → Qwen provides feedback → AI fixes code
Qwen's Role:
- ✅ Reviewer - Analyzes code for security/safety issues
- ✅ Advisor - Points out specific problems
- ❌ NOT an editor - Does not modify code
- ❌ NOT a generator - Only reviews existing code
-
Install Ollama
# Visit https://ollama.ai and install # Or use: curl -fsSL https://ollama.ai/install.sh | sh
-
Pull Qwen Model
ollama pull qwen2.5:0.5b
-
Start Ollama Server
ollama serve
No external Python packages required! Uses only standard library:
jsonreurllib.requestpathlib
from qwen_code_checker import check_response_for_code
# Check a response containing code blocks
response_text = """
Here's a Python function:
```python
def process_input(user_input):
result = eval(user_input) # UNSAFE!
return result"""
result = check_response_for_code(response_text)
if result['has_issues']: print(f"Found {result['total_issues']} issues!") for msg in result['feedback_messages']: print(msg) else: print("No issues found!")
### Advanced Usage
```python
from qwen_code_checker import QwenCodeChecker
# Create checker with custom protocol path
checker = QwenCodeChecker(protocol_path='path/to/custom/protocol.txt')
# Review specific code
review = checker.check_code("""
def login(username, password):
query = f"SELECT * FROM users WHERE username='{username}' AND password='{password}'"
return execute(query)
""", language='python')
print(f"Issues: {review['issues']}")
print(f"Severity: {review['severity']}")
# Generate fix request
fix_request = checker.generate_fix_request({
'has_issues': True,
'feedback_messages': review['feedback']
})
print(fix_request)
qwen-code-checker/
├── qwen_code_checker.py # Main checker module
├── UNIVERSAL_CODE_CRITICALITY_PROTOCOL.txt # UCCP protocol document
├── README.md # This file
├── example_usage.py # Example usage script
└── test_checker.py # Test script
# In your AI response handler
from qwen_code_checker import check_response_for_code, get_code_checker
def handle_ai_response(response_text):
# Review code in response
review = check_response_for_code(response_text)
if review['has_issues']:
# Generate fix request
checker = get_code_checker()
fix_request = checker.generate_fix_request(review)
# Send fix request back to AI
return {
'original_response': response_text,
'has_code_issues': True,
'review': review,
'fix_request': fix_request
}
else:
return {
'original_response': response_text,
'has_code_issues': False
}from qwen_code_checker import QwenCodeChecker
checker = QwenCodeChecker(protocol_path='/path/to/custom/protocol.txt')Default settings (can be modified in code):
OLLAMA_HOST = 'http://localhost:11434' # Ollama server address
QWEN_MODEL = 'qwen2.5:0.5b' # Model to useThe checker reviews code against UCCP principles:
- Assume Hostile Environment - Input validation, dependency trust
- Fail Safely - Error handling, data integrity
- Defense in Depth - Multiple security layers
- Least Privilege - Minimal permissions
- Complete Mediation - Authorization checks
- Input Validation - All inputs validated/sanitized
- Output Encoding - Injection prevention
- Code Extraction: <1ms
- Review per block: 50-200ms
- Total overhead: ~100-500ms for typical responses
- Make sure Ollama is running:
ollama serve - Check Ollama is accessible at
http://localhost:11434
- Pull the model:
ollama pull qwen2.5:0.5b - Verify with:
ollama list
- Ensure
UNIVERSAL_CODE_CRITICALITY_PROTOCOL.txtis in the same directory - Or specify custom path when creating checker
This package includes the Universal Code Criticality Protocol (UCCP) which is a public standard.
Status: ✅ Production Ready
Version: 1.0.0