o
    Zhw                     @   sX   d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ G dd deZdS )	    )CallableListOptional)
BaseLoader)Document)get_client_info)GCSFileLoaderc                   @   sP   e Zd ZdZ		ddedededeeegef  fdd	Zd
e	e
 fddZdS )GCSDirectoryLoaderzLoad from GCS directory. Nproject_namebucketprefixloader_funcc                 C   s   || _ || _|| _|| _dS )a  Initialize with bucket and key name.

        Args:
            project_name: The ID of the project for the GCS bucket.
            bucket: The name of the GCS bucket.
            prefix: The prefix of the GCS bucket.
            loader_func: A loader function that instantiates a loader based on a
                file_path argument. If nothing is provided, the  GCSFileLoader
                would use its default loader.
        N)r   r   r   _loader_func)selfr   r   r   r    r   _/var/www/html/lang_env/lib/python3.10/site-packages/langchain_google_community/gcs_directory.py__init__   s   
zGCSDirectoryLoader.__init__returnc                 C   s   zddl m} W n ty   tdw |j| jtddd}g }|j| j| jdD ]}|j	
dr3q*t| j| j|j	| jd	}||  q*|S )
zLoad documents.r   )storagezCould not import google-cloud-storage python package. Please, install gcs dependency group: `pip install langchain-google-community[gcs]`zgoogle-cloud-storage)module)projectZclient_info)r   /)r   )Zgoogle.cloudr   ImportErrorZClientr   r   Z
list_blobsr   r   nameendswithr   r   extendload)r   r   clientdocsZblobloaderr   r   r   r   #   s(   zGCSDirectoryLoader.load)r
   N)__name__
__module____qualname____doc__strr   r   r   r   r   r   r   r   r   r   r   r	   
   s    
r	   N)typingr   r   r   Zlangchain_core.document_loadersr   Zlangchain_core.documentsr   Z!langchain_google_community._utilsr   Z#langchain_google_community.gcs_filer   r	   r   r   r   r   <module>   s    