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

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_translator-0.1.2.tar.gz
  • Upload date:
  • Size: 2.2 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.2.tar.gz
Algorithm Hash digest
SHA256 5cae5f3f56bef9d412ac79c48b614724f6b88208f0b3203f37d043cdb8ea608e
MD5 ec4ad3776f58d603d71463bef81f9703
BLAKE2b-256 99a20525d4a89c5525b77944aad35d8603f6a09f8102cf66b24e5937f5448042

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_translator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c1ff15eeb79e55b824d78994aad356accef6386a8fd08b3ad55a076f49bb850
MD5 77072fe828fb87d60728193bc656fb2e
BLAKE2b-256 bf5822e10f500f13cb9c205e0a59b1efc6c6c6f3c77b238a0d82ba9d04408b3d

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