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.


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.3.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.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_translator-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 ea78ba6f445fbd2ae213c7fc5bd6645f33b6caeb20506d636d5409c70fc6ddda
MD5 38af0e0723fc76efc6ed2b7764d6581c
BLAKE2b-256 1dea343283d62b7216cc752b02123f645adaf1fa9b5fbf05d1b773d71678e05c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_translator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b0c20643984256cd28fd90a4ce91eca88e494813d88d87cf7eed6be7725dcb56
MD5 c672e4ecf8bdb4aec631de7516396cf6
BLAKE2b-256 0c85246415555607b693b755e3b6ef06299075ea872dc5b63aed8377f528c65a

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