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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file stochasticparrot-0.2.tar.gz.

File metadata

  • Download URL: stochasticparrot-0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for stochasticparrot-0.2.tar.gz
Algorithm Hash digest
SHA256 5a5d7d6cd1c0dbed19552fd6debc662636466bd617874f2f73afbf8218a523da
MD5 26bf9e710b22ef6542dd81f58d84b446
BLAKE2b-256 792d0f9501a55f40e45ede2687d36620122937fa16ec6242c28b57a7d34eccfb

See more details on using hashes here.

File details

Details for the file stochasticparrot-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for stochasticparrot-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e3976ef959e480f4660e95128d47b8e47d6000e2d98a0c6547c657f95fad286
MD5 7390527d8898a2bdf1c73c949fb43ecb
BLAKE2b-256 f02b35a9e0873c0408f22ccebae2e19b2df58ec5406fbb52ff24d1ed68e0330d

See more details on using hashes here.

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