Skip to main content

A Python module to explain exceptions in execution-time using a magic cell

Project description

explainable-exceptions

Artificial Intelligence is being used in several fields, including computer engineering and programming.

During this work, we pretend to facilitate the process of programming as much as possible adding the option to use a NLP (Natural Language Processing) model to help the user to understand and solve the exceptions that may appear while programming.

As simple as using a magic cell, the user will be able to send the exception to the huggingface chat and obtain a possible solution to solve the exception. In this process, the user must be logged in his huggingchat account. Credentials can be saved to be requested only once.

After receiving the response, the user will be able to request another response if the given one is not helpful enough.

Install

To install explainable_exceptions you must use the following pip command:

pip install explainable_exceptions

How to use

In order to use the magic cell, we need to import it from the core of explainable_exceptions. The cell is called explain.

After that, we can label cells using the magic cell command (%%). We can provide a huggingchat user or we can just use the command (if there are not credentials, then it will ask to generate them).

If an exception is raised inside a magic cell, it will be sent to the huggingchat model to generate a possible solution. This response will be shown by the jupyter standard output.

import random

from explainable_exceptions.core import explain

The following cell must be preceded by:

%%explain <username>

Where <username> must be replaced (if provided) by the username of the huggingchat account that will be used to request information.

random.choice([])
CRITICAL:root:Traceback (most recent call last):
  File "/home/ruescog/explainable-exceptions/explainable_exceptions/core.py", line 78, in explain
    exec(cell, globals(), local_ns)
  File "<string>", line 3, in <module>
  File "/grupoa/config/miniconda3/lib/python3.8/random.py", line 290, in choice
    raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

WARNING:root:Be careful, the following response has been generated automatically by a Natural Language Processing Model, so the answer may be incorrect or false.

Huggingchat response (online version):

Hello! That error message suggests that you are trying to use the choice() function from the random module on an empty list or sequence. In order to fix the error, ensure that your code creates and assigns a non-empty sequence for random.choices(). Here is an example of how to create a simple randomized sequence using the list constructor:

import random
seq = [1, 2, 3]
random.shuffle(seq)
print("Shuffled sequence:")
for item in seq:
    print(item)

This should randomly shuffle the elements within the sequence and generate output like this:

Shuffled sequence:
2
3
1

Let me know if there’s something else I could assist you with!


Do you need another answer? (y/n) n

IndexError: Cannot choose from an empty sequence

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

explainable-exceptions-0.0.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

explainable_exceptions-0.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file explainable-exceptions-0.0.3.tar.gz.

File metadata

  • Download URL: explainable-exceptions-0.0.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for explainable-exceptions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0c651c61aec262ab0d8ac2956886a8b256e44ce52eea9d7b8bca9803ed2d4ad1
MD5 a839eb971e77de659a0ded4eaae4f0b4
BLAKE2b-256 6e785a1c0c2256d5963e5432e199b5e820a70acd1d5568d7333308c51668c9d7

See more details on using hashes here.

File details

Details for the file explainable_exceptions-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for explainable_exceptions-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb028c10cbc15900a05e1bc6a0f3329743aa5c56242ddac04e9f163ec7aa7c73
MD5 6e55cd6a9aa552d53b9caacc648a4253
BLAKE2b-256 001bb0b9f454dce1df3f3b4c786af7d1fa0396d0625db7d6d92dccbec26803d2

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