
    dh5                         S SK r S SKrS SKrS SKrS SKJr  S SKJrJrJ	r	J
r
  S SKJr  S SKJr  S SKJrJr  \R$                  " \5      r " S S\5      rg)	    N)Path)DictIteratorListUnion)BaseChatLoader)ChatSession)	AIMessageHumanMessagec                       \ rS rSrSrS\\\4   4S jr\	S\
\   S\4S j5       r\	S\R                  S	\S\
\   4S
 j5       rS\\   4S jrSrg)SlackChatLoader   z0Load `Slack` conversations from a dump zip file.pathc                     [        U[        5      (       a  UO
[        U5      U l        U R                  R                  5       (       d  [	        SU R                   S35      eg)z
Initialize the chat loader with the path to the exported Slack dump zip file.

:param path: Path to the exported Slack dump zip file.
zFile z
 not foundN)
isinstancer   zip_pathexistsFileNotFoundError)selfr   s     ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/chat_loaders/slack.py__init__SlackChatLoader.__init__   sM     !+4 6 6DJ}}##%%#eDMM?*$EFF &    messagesreturnc           
         / nS nU  H  n[        U[        5      (       d  M  UR                  SS5      nUR                  SS5      nUR                  SS5      nU(       d  MY  [        R                  " S[        R
                  S9nUR                  U5      (       a  M  Xb:X  a?  US   =R                  SU-   -  sl        US   R                  S	   R                  S
U05        O UR                  [        UUUS
U0/S.S95        UnM     [        US9$ )Ntext tsuserz<@U\d+> has joined the channel)flagsz

eventsmessage_time)senderr#   )rolecontentadditional_kwargs)r   )r   dictgetrecompile
IGNORECASEmatchr'   r(   appendr   r	   )r   resultsprevious_sendermessager   	timestampr%   skip_patterns           r   _load_single_chat_session)SlackChatLoader._load_single_chat_session   s   8:Ggt,,;;vr*DD"-I[[,F::1L !!$''(##v}4#--h7>>#Y/  # $&,(6	'B&C+	 %O;  < G,,r   zip_file	file_pathc                     U R                  US5       n[        R                  " U5      nSSS5        [        W[        5      (       d  [        S[        U5       35      eU$ ! , (       d  f       N<= f)z"Read JSON data from a zip subfile.rNz#Expected list of dictionaries, got )openjsonloadr   list
ValueErrortype)r7   r8   fdatas       r   
_read_jsonSlackChatLoader._read_jsonC   sX     ]]9c*a99Q<D +$%%B4:,OPP	 +*s   A  
A.c              #   :  #    [         R                  " [        U R                  5      S5       nUR	                  5        H?  nUR                  S5      (       d  M  U R                  X5      nU R                  U5      v   MA     SSS5        g! , (       d  f       g= f7f)z
Lazy load the chat sessions from the Slack dump file and yield them
in the required format.

:return: Iterator of chat sessions containing messages.
r:   z.jsonN)zipfileZipFilestrr   namelistendswithrC   r5   )r   r7   r8   r   s       r   	lazy_loadSlackChatLoader.lazy_loadL   sn      __S/5%..0	%%g..#xCH88BB 1 655s"   +B(B
(B
	B

BB)r   N)__name__
__module____qualname____firstlineno____doc__r   rH   r   r   staticmethodr   r   r	   r5   rF   rG   r)   rC   r   rK   __static_attributes__ r   r   r   r      s    :GCIG !-DJ !-; !- !-F W__  d  C8K0 Cr   r   )r<   loggingr+   rF   pathlibr   typingr   r   r   r   langchain_core.chat_loadersr   langchain_core.chat_sessionsr	   langchain_core.messagesr
   r   	getLoggerrM   loggerr   rT   r   r   <module>r]      sC      	   . . 6 4 ;			8	$HCn HCr   