Skip to main content

Translate Python errors into AI-explained suggestions.

Project description

ErrorTranslator

ErrorTranslator is a Python library that translates Python error tracebacks into clear, actionable explanations using AI-powered translation models. It supports multiple backends including OpenAI GPT, HuggingFace models, and local models.


Features

  • Translate Python exceptions into easy-to-understand suggestions.
  • Supports OpenAI GPT, HuggingFace remote models, and local HuggingFace models.
  • Caches translations to avoid repeated API calls.
  • Displays nicely formatted error and translation outputs using Rich.
  • Supports asynchronous translation.

Installation

pip install error-translator

Requirements

  • Python 3.7+
  • rich
  • python-dotenv
  • openai
  • transformers

Usage

import os
from error_translator import ErrorTranslator

# Load your OpenAI API key from environment variables
api_key = os.getenv("OPENAI_API_KEY")

translator = ErrorTranslator.with_openai(api_key=api_key)

def buggy_function():
    return 1 / 0

try:
    buggy_function()
except Exception as e:
    translator.translate_error(e)

Available Models

  • ErrorTranslator.with_openai(api_key, model="gpt-4o")
  • ErrorTranslator.with_huggingface(model_name)
  • ErrorTranslator.with_local_huggingface(directory_path)
  • ErrorTranslator.with_custom_model(custom_model_instance)

Environment Variables

Create a .env file in your project root with:

OPENAI_API_KEY=your_openai_api_key_here

Development & Contribution

Feel free to open issues or submit pull requests!


License

This project is licensed under the MIT License.


Acknowledgments

Built using Rich for beautiful console output and various AI translation models.


Example Output

Error Translator Logs

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_translator-0.1.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

error_translator-0.1.5-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file error_translator-0.1.5.tar.gz.

File metadata

  • Download URL: error_translator-0.1.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for error_translator-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a5e50d2e6818d776e7a0f7b061a015686e3de422ada8cae117a1b9e24afb27d6
MD5 559b26616c29c06ed7e230940013f45e
BLAKE2b-256 95c856602f54cf63f71f0880dad3c25c9dcf0c99e15de5a39add42f947de522e

See more details on using hashes here.

File details

Details for the file error_translator-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for error_translator-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 30fd79c1fa0ee4c61cd0dd2459b0f715f683feebd870ee05eba40e2e41b717c3
MD5 c912c37cd6eb46595c25957c2885f334
BLAKE2b-256 0d65fa0bceb753370bdb6ee8a5d7d92e6fbd946d18970230a42fe1afba9d2ff1

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