Skip to main content

A package for handling errors with custom logging that lets OpenAI API make suggestions.

Project description

Custom Error Handler: Stochastic Parrot

Stochastic Parrot is a Python package that provides a robust way to handle uncaught exceptions in your Python scripts. It logs error details, displays them in a color-coded console output, and leverages OpenAI to suggest fixes.

Features:

  • Colored Console Logging: Utilizes different colors for log levels like DEBUG, INFO, WARNING, ERROR, and CRITICAL.
  • File Logging: Automatically logs errors to a file named 'automated_error_handling.log'.
  • Traceback Capture: Gathers detailed traceback information including surrounding lines of code where the error occurred.
  • OpenAI Integration: Sends error information to OpenAI's GPT-4 model to get suggested fixes.

How to Use:

  1. Installation: Install the package using pip install stochastic-parrot.
  2. Initialization: Import and initialize Stochastic Parrot in your script: import stochastic_parrot stochastic_parrot.initialize()

Components:

  • ColoredConsoleHandler: A custom logging handler class that extends logging.StreamHandler. It allows for log messages to be printed to the console in different colors based on the log level.
  • custom_error_handler: A function to be set as sys.excepthook to handle uncaught exceptions. It captures the traceback, reads surrounding code, logs the details, and calls the OpenAI API to suggest fixes.
  • openai_chat_completion_base_query: A function to query OpenAI's GPT-4 model. It sends the error details and receives a suggested code fix in response.
  • initialize: A function to initialize Stochastic Parrot. It sets up the OpenAI API key and sys.excepthook.

Requirements:

  • openai: To interact with the OpenAI API.
  • termcolor: To colorize the console output.
  • getpass: To get the OpenAI API key from the user.
  • logging: To log the error details.
  • sys: To set the custom error handler as sys.excepthook.
  • traceback: To capture the traceback.

License:

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

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stochasticparrot-0.2.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

stochasticparrot-0.2-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page