Skip to main content

A package for detecting errors and generating solutions using an LLM API.

Project description

🌟 ErrorDetect: AI-Powered Python Error Fixing

PyPI version Python version License: MIT

ErrorDetect is a Python package that automatically captures, analyzes, and fixes errors using a Large Language Model (LLM). It integrates with Ollama LLM APIs to return only the corrected line of code for detected errors.


🚀 Features

Automatic Error Capture – Detects exceptions and captures error details.
AI-Powered Fixes – Uses LLMs (like Llama3) to generate corrected lines of code.
Traceback Extraction – Captures the exact line of code causing the error.
Flexible Integration – Works with or without LLM integration.


👥 Installation

You can install error_detect directly from PyPI:

pip install error_detect

Or install it from source:

git clone https://github.com/Rhul27/error_detect.git
cd error_detect
pip install .

🛠️ Usage

1️⃣ Basic Usage (Without LLM Integration)

You can use ErrorDetect to capture and display error details:

from error_detect import ErrorDetect

client = ErrorDetect()

try:
    a = 1 / 0
except Exception:
    print(client.error_detect())

Output:

Type: ZeroDivisionError
Line: 10
Error: division by zero

2️⃣ Using an LLM to Automatically Fix Errors

If you have an Ollama-compatible API running, you can connect to an AI model to fix errors automatically:

from error_detect import ErrorDetect

client = ErrorDetect("http://localhost:11434", "llama3.2")

try:
    a = 1 / 0
except Exception:
    output = client.get_error_solution()
    print(output)

Example Output:

Type: ZeroDivisionError
Line: 12
Error: division by zero
Solution : "a = 1.0 / (0.0001)  # Avoid division by zero"

3️⃣ Handling Missing Dictionary Keys (KeyError Example)

try:
    data = {"name": "Alice"}
    print(data["age"])  # This key does not exist
except Exception:
    output = client.get_error_solution()
    print(output)

Output:

Type: KeyError
Line: 15
Error: 'age'
Solution : "age = data.get('age', 25)  # Provide a default value"

⚙️ API Reference

ErrorDetect(ollama_url=None, model_name=None)

Parameters:

  • ollama_url (str, optional) – The base URL of the Ollama LLM server.
  • model_name (str, optional) – The name of the LLM model to use.

error_detect()

Returns:
Returns a string containing error details:

Type: <ExceptionType>
Line: <LineNumber>
Error: <ErrorMessage>

get_error_solution(error_message=None, error_line=None)

Automatically detects errors and gets the corrected code line using LLM.

Returns:
Formatted output with both the error details and the solution:

Type: <ExceptionType>
Line: <LineNumber>
Error: <ErrorMessage>
Error line : <ErrorLine>
Solution : "<Corrected Line of Code>"

If LLM is not integrated, returns:

LLM integration not configured.

🌍 Environment Setup

To use the AI-powered error detection, ensure you have an Ollama LLM server running locally:

ollama serve

You can check available models via:

curl http://localhost:11434/api/tags

🛠️ Troubleshooting

Problem: I get LLM integration not configured.
👉 Solution: Pass a valid ollama_url and model_name when initializing ErrorDetect.

Problem: LLM does not return a proper fix.
👉 Solution: Try a different model like "codellama" for better code-specific fixes.


🤝 Contributing

We welcome contributions! Follow these steps to contribute:

  1. Fork the repository.
  2. Create a new feature branch (git checkout -b feature-branch).
  3. Commit changes (git commit -m "Added new feature").
  4. Push to your fork (git push origin feature-branch).
  5. Open a Pull Request.

📃 License

This project is licensed under the MIT License. See LICENSE for details.


📞 Contact

📧 Email: 27rg2000@gmail.com 🔗 GitHub: Rhul27/error_detect


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

error_detect-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

error_detect-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_detect-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for error_detect-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b7ffd1733970b491af398c780757226f1feba5731fa811ad966dae0ebed6989
MD5 9ce22776eeb1a8ba7801fa8c79cbc6f8
BLAKE2b-256 073532e54e88847b5bdef145e96bf896a10ebb3b2b143e648b15c67c3a9a0473

See more details on using hashes here.

File details

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

File metadata

  • Download URL: error_detect-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for error_detect-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cfe6911244c7cfcecaf0c370acc0215a03cc78bdb2684291d822d2613b8f4e4
MD5 c4eddb65cade8b0d9db897b61856cbc4
BLAKE2b-256 231d31c5463b4bbbc6dbb85dfe8ddaba907203ced50adc1371320aed3bc815a3

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