o
    RTh                  	   @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZmZmZ ddlmZ 		dd
ddee dedefddZdddZd	S )z
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.
    )TracebackException)TracebackType)Type)InteractiveShellget_ipython)PastAssists
PastErrors)GenaiMarkdownStagecan_handle_display_updates)generate_exception_suggestionNshellr   etypeevaluetbc              
   C   s  | j |||f|d |tkrd S |tkrd S z}d }| j}| jd }| j}|d ur8|t|jd kr8| jj| }n|d urI|t|d krI|| }nd }tdt	j
d}	|	  t|||ddjdd	}
d
|
}t|||| t||	 t }t|||||d}t	j|	_d|	_|	| t	j|	_W d S  ty } ztd| W Y d }~d S d }~w ty   dt v rd|	_d |	_Y d S Y d S w )N)	tb_offsetIn   u%   Let's see how we can fix this... 🔧)stage   )limitT)chain
)coder   r   plaintext_tracebackstreamu   ## 💡 Suggestion
z,Error while trying to provide a suggestion: gm )showtracebackKeyboardInterrupt
SystemExitexecution_countuser_nshistory_managerleninput_hist_rawr	   r
   STARTINGdisplayr   formatjoinr   addr   r   r   
GENERATINGr   messageconsumeFINISHED	Exceptionprintlocals)r   r   r   r   r   r   r!   r   r#   r   	formattedr   r   
suggestione r5   T/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/genai/suggestions.py
custom_exc   s\   




r7   c                 C   s    | du rt  } | tft dS )z?Register the exception handler with the given IPython instance.N)r   set_custom_excr/   r7   )ipythonr5   r5   r6   registera   s   r:   )N)__doc__	tracebackr   typesr   typingr   IPythonr   r   genai.contextr   r   genai.displayr	   r
   r   genai.generater   BaseExceptionr7   r:   r5   r5   r5   r6   <module>   s&    	
N