o
    Zh                     @   s\   d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	 G dd de	Z
G dd de
ZdS )	    N)AnyIterator)Document)
BaseLoaderc                   @   sJ   e Zd ZdZdededefddZdedefd	d
Zdee	 fddZ
dS )LarkSuiteDocLoaderz!Load from `LarkSuite` (`FeiShu`).domainaccess_tokendocument_idc                 C   s   || _ || _|| _dS )zInitialize with domain, access_token (tenant / user), and document_id.

        Args:
            domain: The domain to load the LarkSuite.
            access_token: The access_token to use.
            document_id: The document_id to load.
        N)r   r   r	   )selfr   r   r	    r   e/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/larksuite.py__init__   s   
zLarkSuiteDocLoader.__init__api_urlreturnc                 C   sf   dd| j  i}tjj||d}tj|}t|  }|W  d   S 1 s,w   Y  dS )z.Get LarkSuite (FeiShu) API response json data.AuthorizationzBearer )headersN)	r   urllibrequestRequesturlopenjsonloadsreaddecode)r
   r   r   r   responseZ	json_datar   r   r   _get_larksuite_api_json_data   s   $z/LarkSuiteDocLoader._get_larksuite_api_json_datac                 c   s    | j  d}| | d| j }| | d| j d}|d d }| j|d d d |d d d d	}t||d
V  dS )z&Lazy load LarkSuite (FeiShu) document.z/open-apis/docx/v1/documents/z/raw_contentdatacontentZdocumentrevision_idtitle)r	   r   r    )Zpage_contentmetadataN)r   r   r	   r   )r
   Zapi_url_prefixZmetadata_jsonZraw_content_jsontextr!   r   r   r   	lazy_load!   s   zLarkSuiteDocLoader.lazy_loadN)__name__
__module____qualname____doc__strr   r   r   r   r   r#   r   r   r   r   r   
   s
    r   c                       s@   e Zd ZdZdededefddZdee f fdd	Z  Z	S )
LarkSuiteWikiLoaderz&Load from `LarkSuite` (`FeiShu`) wiki.r   r   wiki_idc                 C   s   || _ || _|| _d| _dS )zInitialize with domain, access_token (tenant / user), and wiki_id.

        Args:
            domain: The domain to load the LarkSuite.
            access_token: The access_token to use.
            wiki_id: The wiki_id to load.
         N)r   r   r*   r	   )r
   r   r   r*   r   r   r   r   6   s   
zLarkSuiteWikiLoader.__init__r   c                 #   sP    | j s| j d}| | d| j }|d d d | _ t  E dH  dS )z+Lazy load LarkSuite (FeiShu) wiki document.z"/open-apis/wiki/v2/spaces/get_nodez?token=r   nodeZ	obj_tokenN)r	   r   r   r*   superr#   )r
   Zwiki_url_prefixZwiki_node_info_json	__class__r   r   r#   C   s   zLarkSuiteWikiLoader.lazy_load)
r$   r%   r&   r'   r(   r   r   r   r#   __classcell__r   r   r.   r   r)   3   s    r)   )r   urllib.requestr   typingr   r   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   r   r)   r   r   r   r   <module>   s    )