
    Ng                         d dl Z d dlZ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 d dlmZ  edd	d
           G d de                      ZdS )    N)CallableListOptional)
deprecated)Document)
BaseLoaderUnstructuredFileLoader)get_client_infoz0.0.32z1.0z(langchain_google_community.GCSFileLoader)sinceremovalalternative_importc                   d    e Zd ZdZ	 d
dedededeeegef                  fdZde	e
         fd	ZdS )GCSFileLoaderzLoad from GCS file.Nproject_namebucketblobloader_funcc                 j    || _         || _        || _        dt          dt          fd}|r|n|| _        dS )a9  Initialize with bucket and key name.

        Args:
            project_name: The name of the project to load
            bucket: The name of the GCS bucket.
            blob: The name of the GCS blob to load.
            loader_func: A loader function that instantiates a loader based on a
                file_path argument. If nothing is provided, the
                UnstructuredFileLoader is used.

        Examples:
            To use an alternative PDF loader:
            >> from from langchain_community.document_loaders import PyPDFLoader
            >> loader = GCSFileLoader(..., loader_func=PyPDFLoader)

            To use UnstructuredFileLoader with additional arguments:
            >> loader = GCSFileLoader(...,
            >>      loader_func=lambda x: UnstructuredFileLoader(x, mode="elements"))

        	file_pathreturnc                      t          |           S Nr	   )r   s    i/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/gcs_file.pydefault_loader_funcz3GCSFileLoader.__init__.<locals>.default_loader_func4   s    ))444    N)r   r   r   strr   _loader_func)selfr   r   r   r   r   s         r   __init__zGCSFileLoader.__init__   sV    6 	(	53 	5: 	5 	5 	5 	5 ,7OKK<Or   r   c                 $   	 ddl m} n# t          $ r t          d          w xY w|                    | j        t          d                    }|                    | j                  }|                    | j                  }|	                    | j                  j
        }t          j                    5 }| d| j         }t          j        t          j                            |          d           |                    |           |                     |          }|                                }	|	D ]A}
d	|
j
        v rd
| j         d| j         |
j
        d	<   |r|
j
                            |           B|	cddd           S # 1 swxY w Y   dS )zLoad documents.r   )storagezpCould not import google-cloud-storage python package. Please install it with `pip install google-cloud-storage`.zgoogle-cloud-storage)client_info/T)exist_oksourcezgs://N)google.cloudr"   ImportErrorClientr   r   
get_bucketr   r   get_blobmetadatatempfileTemporaryDirectoryosmakedirspathdirnamedownload_to_filenamer   loadupdate)r   r"   storage_clientr   r   r,   temp_dirr   loaderdocsdocs              r   r4   zGCSFileLoader.load9   s   	,,,,,,, 	 	 	M  	 !?;Q+R+R ( 
 
  **4;77{{49%%??49--6(** 	h#11di11IK	22TBBBB%%i000&&y11F;;==D 2 2s|++-NT[-N-N49-N-NCL* 2L''111	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   	 #5CFF	F	r   )__name__
__module____qualname____doc__r   r   r   r   r    r   r   r4    r   r   r   r      s          >B"P "P"P "P 	"P
 huj'89:"P "P "P "PH d8n            r   r   )r/   r-   typingr   r   r   langchain_core._api.deprecationr   langchain_core.documentsr   )langchain_community.document_loaders.baser   1langchain_community.document_loaders.unstructuredr
   &langchain_community.utilities.vertexair   r   r?   r   r   <module>rF      s    				  + + + + + + + + + + 6 6 6 6 6 6 - - - - - - @ @ @ @ @ @ T T T T T T B B B B B B 
A  
G G G G GJ G G 
G G Gr   