Skip to main content

AI-powered Python debugging assistant โ€” ChatGPT for Python errors

Project description

PyDebugAI ๐Ÿ›

AI-powered Python debugging assistant โ€” like ChatGPT, but exclusively for Python errors. Installable via pip. Runs in your terminal and in VSCode.


Features

Feature Description
๐Ÿ” AST Static Analysis Catches errors before running โ€” undefined names, division by zero, type mismatches
๐Ÿค– Rule Engine 60+ hand-crafted rules for instant, deterministic fixes
๐Ÿง  ML Classifier TF-IDF + Random Forest classifies error types with high confidence
๐Ÿ“ Levenshtein Fixer Detects typos in variable/function names and suggests corrections
๐Ÿš€ CodeBERT Deep semantic code understanding via HuggingFace transformers
๐Ÿ“š Self-Learning SQLite + RLHF-lite โ€” improves from every upvote/downvote
๐Ÿงฉ VSCode Extension Red squiggles, hover hints, quick-fix menu, sidebar chat panel
๐Ÿ’ป CLI Runner pydebugai run file.py โ€” run and debug from your terminal

Quick Start

1. Install via pip

pip install pydebugai

Or install from source (this repo):

cd c:\new-model-ai
pip install -e .

2. Run the CLI

# Analyze a Python file
pydebugai run my_script.py

# Interactive chat mode (paste code or errors)
pydebugai chat

# Start the local API server (required for VSCode extension)
pydebugai serve

# Show self-learning statistics
pydebugai stats

3. Install the VSCode Extension

# Install from .vsix (after packaging)
code --install-extension vscode-extension/pydebugai-0.1.0.vsix

Or in VSCode: Extensions โ†’ Install from VSIX...

Then start the server in your terminal:

pydebugai serve

The extension will:

  • Show red squiggles on error lines
  • Display hover hints with fix suggestions
  • Offer ๐Ÿ’ก Fix with PyDebugAI in the quick-fix menu
  • Open the sidebar panel with full AI analysis

AI Algorithms

User Code
    โ”‚
    โ”œโ”€โ–บ AST Analyzer (static, instant)
    โ”‚       โ””โ”€ SyntaxError, IndentationError, undefined names,
    โ”‚          division by zero, comparison style warnings
    โ”‚
    โ”œโ”€โ–บ Code Executor (subprocess, safe)
    โ”‚       โ””โ”€ Captures stdout / stderr / exit code
    โ”‚
    โ”œโ”€โ–บ Error Parser (regex traceback parser)
    โ”‚       โ””โ”€ Extracts: exception type, message, file, line, col
    โ”‚
    โ”œโ”€โ–บ Rule Engine (60+ rules, deterministic)
    โ”‚       โ””โ”€ Pattern-match โ†’ instant fix suggestion
    โ”‚
    โ”œโ”€โ–บ ML Classifier (TF-IDF + Random Forest)
    โ”‚       โ””โ”€ Classifies error type โ†’ boosts rule confidence
    โ”‚
    โ”œโ”€โ–บ Levenshtein Fixer (edit distance)
    โ”‚       โ””โ”€ "Did you mean 'print'?" for NameError/AttributeError
    โ”‚
    โ”œโ”€โ–บ CodeBERT (HuggingFace, optional)
    โ”‚       โ””โ”€ Semantic embeddings โ†’ cosine similarity retrieval
    โ”‚
    โ””โ”€โ–บ Orchestrator โ†’ Merge, Deduplicate, Rank by confidence
                โ””โ”€โ–บ Top-10 suggestions โ†’ CLI / VSCode / API

Self-Learning Loop (RLHF-lite)

User gives thumbs-up / thumbs-down on suggestion
    โ†’ Stored in SQLite (pydebugai/data/feedback.db)
    โ†’ Positive samples accumulate
    โ†’ Every 25 positive samples โ†’ auto-retrain ML classifier
    โ†’ Model improves over time per user

CLI Examples

# Run and auto-debug a buggy file
pydebugai run tests/samples/buggy_sample.py

# Get output as JSON (pipe to other tools)
pydebugai run my_script.py --json

# Static analysis only (don't execute)
pydebugai run my_script.py --no-exec

# Deep analysis with CodeBERT (slower)
pydebugai run my_script.py --deep

# Interactive REPL
pydebugai chat
>>> x = 10 / 0
# (press Enter twice)
# โ†’ AI prints fix suggestions

API (for VSCode extension & custom integrations)

Start server: pydebugai serve (default: http://localhost:7432)

# Analyze code
curl -X POST http://localhost:7432/analyze \
  -H "Content-Type: application/json" \
  -d '{"code": "print(udefined)"}'

# Record feedback
curl -X POST http://localhost:7432/feedback \
  -H "Content-Type: application/json" \
  -d '{"interaction_id": 1, "selected_idx": 0, "feedback": 1}'

# Health check
curl http://localhost:7432/status

# Stats
curl http://localhost:7432/stats

Requirements

Minimal (fast startup, no ML)

click, rich, fastapi, uvicorn, pydantic

Full AI features

scikit-learn    # ML classifier
transformers    # CodeBERT
torch           # PyTorch backend
python-Levenshtein  # fast edit distance

Install all:

pip install -r requirements.txt

Running Tests

cd c:\new-model-ai
python tests/test_error_parser.py
python tests/test_ast_analyzer.py
python tests/test_rule_engine.py

VSCode Extension Settings

Setting Default Description
pydebugai.serverPort 7432 Local server port
pydebugai.analyzeOnSave true Auto-analyze on save
pydebugai.enableExecution false Run code during analysis
pydebugai.pythonPath python Python interpreter path

License

MIT ยฉ PyDebugAI Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydebugai-0.1.0.tar.gz (685.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydebugai-0.1.0-py3-none-any.whl (700.6 kB view details)

Uploaded Python 3

File details

Details for the file pydebugai-0.1.0.tar.gz.

File metadata

  • Download URL: pydebugai-0.1.0.tar.gz
  • Upload date:
  • Size: 685.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pydebugai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18c1236e612a258205135baaa4ee33fc81c5159711a040c1b4e76196c3e7f4d3
MD5 0ce32d3954999748c6fee87694d97d5b
BLAKE2b-256 37550d18f23882bbce0f259956616c46a42ce9c8386ea516f72d64cee77bc3d1

See more details on using hashes here.

File details

Details for the file pydebugai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydebugai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 700.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pydebugai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f266f451a472c399ac880317fdad7f1eee6185165820e4ef3e83aa3cd381def1
MD5 1c64a138992442c2ecc5eb7638781c63
BLAKE2b-256 126fd47b822ea834478fccf56bd19adaa231f3300cd5c8c9f5db1e02a34eb3b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page