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
  • Other dependencies depending on model backends (e.g., 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.

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.1.tar.gz (2.1 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.1-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_translator-0.1.1.tar.gz
  • Upload date:
  • Size: 2.1 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.1.tar.gz
Algorithm Hash digest
SHA256 41e20a14c6224eab9ad4373b5862a978e374eea8380d66de3e0bd2408675436d
MD5 ed0b229356f5b1c644f532c6819337fe
BLAKE2b-256 6ca9081a01082b61212acb787cf2065c4c9e2b12daabf937bd990377d1d18ee9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_translator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfc0629ba591c40813be46d028e32a179e0f3fda68de76e0994535959f146e8d
MD5 bef6a68c51e3ea9b593ca23b6871702e
BLAKE2b-256 77b0d77a87502cb16d12a002429cbcc7c4243111050a5b19104f3313f814d017

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