
    ih              
           d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ deded	ed
edef
dZdedefdZ G d de      Zy)zLoads .ipynb notebook files.    N)Path)AnyListUnion)Document)
BaseLoadercellinclude_outputsmax_output_length	tracebackreturnc                 x   | d   }| d   }|r	 | d   }|r|dk(  rrd|d   j                         v r;|d   d   }|d   d   }|r|d   d   }d	| d
| d| d| d| dS d	| d
| d| d| d	S |d   d   dk(  r,|d   d   }t        |t        |            }	d	| d
| d|d|	  dS yd	| d
| dS # t         $ r Y w xY w)as  Combine cells information in a readable format ready to be used.

    Args:
        cell: A dictionary
        include_outputs: Whether to include the outputs of the cell.
        max_output_length: Maximum length of the output to be displayed.
        traceback: Whether to return a traceback of the error.

    Returns:
        A string with the cell information.

    	cell_typesourceoutputscodeenamer   evaluer   'z	' cell: 'z'
, gives error 'z', with description 'z'
and traceback 'z'

z',with description 'output_typestreamtextz'
 with output: 'N )KeyErrorkeysminlen)
r	   r
   r   r   r   r   output
error_nameerror_value
min_outputs
             k/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/notebook.pyconcatenate_cellsr#      se    [!I(^F	)_F 9.6fQinn&&7+J )H-K"1Ik2		{)F83Ej\ R**5 7&&/[7 	{)F83Ej\ R))4U< AY}%1AYv&F.F<JI;ix 0";J/07  9+Yvhe447  		s   B- -	B98B9xc                 ,   t        | t              r| j                  dd      S t        | t              r| D cg c]  }t	        |       c}S t        | t
              r-| j                         D ci c]  \  }}|t	        |       c}}S | S c c}w c c}}w )zMRecursively remove newlines, no matter the data structure they are stored in.
r   )
isinstancestrreplacelistremove_newlinesdictitems)r$   elemkvs       r"   r+   r+   @   s{     !Syyr""	At	234$%44	At	45GGI>&1a?1%%>>	 5>s   B/Bc                   R    e Zd ZdZ	 	 	 	 ddeeef   dedededef
dZ	de
e   fd	Zy
)NotebookLoaderz'Load `Jupyter notebook` (.ipynb) files.pathr
   r   remove_newliner   c                 J    || _         || _        || _        || _        || _        y)a  Initialize with a path.

        Args:
            path: The path to load the notebook from.
            include_outputs: Whether to include the outputs of the cell.
                Defaults to False.
            max_output_length: Maximum length of the output to be displayed.
                Defaults to 10.
            remove_newline: Whether to remove newlines from the notebook.
                Defaults to False.
            traceback: Whether to return a traceback of the error.
                Defaults to False.
        N)	file_pathr
   r   r4   r   )selfr3   r
   r   r4   r   s         r"   __init__zNotebookLoader.__init__P   s*    * .!2,"    r   c                     t         j                        }t        |d      5 }t        j                  |      }ddd       d   D cg c]+  }|j                         D ci c]  \  }}|dv s|| c}}- }}}} j                  rt        t        t        |            }dj                  t        t         fd|                  }dt        |      i}	t        ||		      gS # 1 sw Y   xY wc c}}w c c}}}w )
zLoad documents.utf8)encodingNcells)r   r   r   r   c                 \    t        | j                  j                  j                        S )N)r#   r
   r   r   )r$   r7   s    r"   <lambda>z%NotebookLoader.load.<locals>.<lambda>   s&    /4//1G1G r9   r   )page_contentmetadata)r   r6   openjsonloadr-   r4   r*   mapr+   joinr(   r   )
r7   pfdr	   r/   r0   filtered_datar   rA   s
   `         r"   rD   zNotebookLoader.loadk   s      !f% 			!A	
 '

 
 !%

Xfq!5W0WQTX
 

  _m!DEMww "		
 c!f%dX>??1	 	 Y
s)   C&C8#C20C25C8&C/2C8N)F
   FF)__name__
__module____qualname____doc__r   r(   r   boolintr8   r   r   rD    r9   r"   r2   r2   M   sd    1
 !&!#$#CI# # 	#
 # #6@	h@r9   r2   )rO   rC   pathlibr   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   r,   rP   rQ   r(   r#   r+   r2   rR   r9   r"   <module>rW      si    "   # # - @1
1!%1:=1JN11h
s 
s 
<@Z <@r9   