Skip to content

A standalone code review system using Qwen2.5-0.5B to review AI-generated code against the Universal Code Criticality Protocol (UCCP).

License

Notifications You must be signed in to change notification settings

jsolo222/qwen_code_checker

Repository files navigation

Qwen Code Checker

A standalone code review system using Qwen2.5-0.5B to review AI-generated code against the Universal Code Criticality Protocol (UCCP).

Features

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)

How It Works

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

Installation

Prerequisites

  1. Install Ollama

    # Visit https://ollama.ai and install
    # Or use: curl -fsSL https://ollama.ai/install.sh | sh
  2. Pull Qwen Model

    ollama pull qwen2.5:0.5b
  3. Start Ollama Server

    ollama serve

Python Requirements

No external Python packages required! Uses only standard library:

  • json
  • re
  • urllib.request
  • pathlib

Quick Start

Basic Usage

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

"""

Review the code

result = check_response_for_code(response_text)

Check results

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)

File Structure

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

Integration Example

Integration with AI Chat System

# 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
        }

Configuration

Custom Protocol Path

from qwen_code_checker import QwenCodeChecker

checker = QwenCodeChecker(protocol_path='/path/to/custom/protocol.txt')

Ollama Configuration

Default settings (can be modified in code):

OLLAMA_HOST = 'http://localhost:11434'  # Ollama server address
QWEN_MODEL = 'qwen2.5:0.5b'              # Model to use

What Gets Reviewed

The checker reviews code against UCCP principles:

  1. Assume Hostile Environment - Input validation, dependency trust
  2. Fail Safely - Error handling, data integrity
  3. Defense in Depth - Multiple security layers
  4. Least Privilege - Minimal permissions
  5. Complete Mediation - Authorization checks
  6. Input Validation - All inputs validated/sanitized
  7. Output Encoding - Injection prevention

Performance

  • Code Extraction: <1ms
  • Review per block: 50-200ms
  • Total overhead: ~100-500ms for typical responses

Troubleshooting

"Ollama connection error"

  • Make sure Ollama is running: ollama serve
  • Check Ollama is accessible at http://localhost:11434

"Qwen model not found"

  • Pull the model: ollama pull qwen2.5:0.5b
  • Verify with: ollama list

"Protocol file not found"

  • Ensure UNIVERSAL_CODE_CRITICALITY_PROTOCOL.txt is in the same directory
  • Or specify custom path when creating checker

License

This package includes the Universal Code Criticality Protocol (UCCP) which is a public standard.


Status: ✅ Production Ready
Version: 1.0.0

About

A standalone code review system using Qwen2.5-0.5B to review AI-generated code against the Universal Code Criticality Protocol (UCCP).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages