๐ง AI-Powered Coding AssistantsMay 25, 2026โ
Tests passing
Bug Sleuth
A Python library that integrates with AI-powered debugging models to identify potential bugs in Python code. Developers can run their scripts through the library to get suggestions for problematic code segments and fixes, speeding up debugging workflows.
What It Does
- Analyze Python scripts or raw code for potential bugs.
- Get detailed suggestions for fixes.
- Handles invalid Python code gracefully.
- Provides meaningful error messages for missing files or API issues.
Installation
- Python 3.7+
- loguru
- openai
Usage
To run the tests, install pytest and run the following command:
pip install pytest
pytest test_bug_sleuth.pySource Code
import ast
import json
from loguru import logger
import openai
def analyze_code(input_code_or_file):
"""
Analyzes Python code for potential bugs using an AI-powered model.
Args:
input_code_or_file (str): Python code as a string or a file path to a Python script.
Returns:
dict: JSON report containing identified bugs and suggested fixes.
"""
try:
# Determine if input is a file or raw code
if input_code_or_file.endswith('.py'):
try:
with open(input_code_or_file, 'r') as file:
code = file.read()
except FileNotFoundError:
logger.error("File not found.")
return {
"error": "File not found.",
"details": "The specified file does not exist."
}
else:
code = input_code_or_file
# Parse the code to ensure it's valid Python
try:
ast.parse(code)
except SyntaxError as e:
return {
"error": "Invalid Python code.",
"details": str(e)
}
# Send code to OpenAI for analysis
logger.info("Sending code to OpenAI for analysis...")
try:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a Python debugging assistant."},
{"role": "user", "content": f"Analyze this Python code for potential bugs and suggest fixes: {code}"}
]
)
except openai.error.OpenAIError as e:
logger.error("OpenAI API error: {}", e)
return {
"error": "OpenAI API error.",
"details": str(e)
}
# Extract response
suggestions = response['choices'][0]['message']['content']
return {
"code": code,
"analysis": suggestions
}
except Exception as e:
logger.error("Unexpected error: {}", e)
return {
"error": "Unexpected error.",
"details": str(e)
}
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Bug Sleuth: AI-powered Python code analysis tool.")
parser.add_argument("input", type=str, help="Python script file or string input containing code.")
args = parser.parse_args()
result = analyze_code(args.input)
print(json.dumps(result, indent=4))Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- bug_sleuth
- Category
- AI-Powered Coding Assistants
- Generated
- May 25, 2026
- Tests
- Passing โ
- Fix Loops
- 3
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-05-25/bug_sleuth cd generated_tools/2026-05-25/bug_sleuth pip install -r requirements.txt 2>/dev/null || true python bug_sleuth.py