[docs]classTencentCOSFileLoader(BaseLoader):"""Load from `Tencent Cloud COS` file."""
[docs]def__init__(self,conf:Any,bucket:str,key:str):"""Initialize with COS config, bucket and key name. :param conf(CosConfig): COS config. :param bucket(str): COS bucket. :param key(str): COS file key. """self.conf=confself.bucket=bucketself.key=key
[docs]deflazy_load(self)->Iterator[Document]:"""Load documents."""try:fromqcloud_cosimportCosS3ClientexceptImportError:raiseImportError("Could not import cos-python-sdk-v5 python package. ""Please install it with `pip install cos-python-sdk-v5`.")# initialize a clientclient=CosS3Client(self.conf)withtempfile.TemporaryDirectory()astemp_dir:file_path=f"{temp_dir}/{self.bucket}/{self.key}"os.makedirs(os.path.dirname(file_path),exist_ok=True)# Download the file to a destinationclient.download_file(Bucket=self.bucket,Key=self.key,DestFilePath=file_path)loader=UnstructuredFileLoader(file_path)# UnstructuredFileLoader not implement lazy_load yetreturniter(loader.load())