Skip to content

suggestions

This module creates a custom exception handler that will send the error to OpenAI's ChatGPT in order to help debug the code. It will also display the error in the notebook as usual.

Stage #

Bases: str, Enum

The stage of feedback generation

Source code in genai/suggestions.py
39
40
41
42
43
44
class Stage(str, Enum):
    """The stage of feedback generation"""

    STARTING = "starting"
    GENERATING = "generating"
    FINISHED = "finished"

can_handle_display_updates() #

Determine (roughly) if the client can handle display updates.

Source code in genai/suggestions.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def can_handle_display_updates():
    """Determine (roughly) if the client can handle display updates."""
    try:
        from IPython import get_ipython

        ipython = get_ipython()
        if ipython is None:
            return False

        name = ipython.__class__.__name__

        if name == "ZMQInteractiveShell":
            return True
        elif name == "TerminalInteractiveShell":
            return False
        else:
            # Just assume they can otherwise
            return True
    except ImportError:
        # No IPython, so no display updates whatsoever
        return False

register(ipython=None) #

Register the exception handler with the given IPython instance.

Source code in genai/suggestions.py
144
145
146
147
148
149
def register(ipython=None):
    """Register the exception handler with the given IPython instance."""
    if ipython is None:
        ipython = get_ipython()

    ipython.set_custom_exc((Exception,), custom_exc)