o
    g*	                     @   sn   d dl Z d dlZd dlmZ d dl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	ZdS )
    N)DocUploader)S3BucketStorageget_default_bucket_name)Project)DynamoDB)ThreadPoolExecutor)ClientConfigc                   @   sH   e Zd ZdedefddZdedefddZ				dd
edefddZdS )ChatDocumentUploaderprojectclient_configc                 C   s   || _ || _d S )N)r
   r   )selfr
   r    r   ,/var/www/html/XCapMarket/utils/chat/index.py__init__   s   
zChatDocumentUploader.__init__bucket_namedoc_pathc              
   C   s   z'	 d| d| }t | j| j|}d| jj |_|  td| d W d S  tyB } ztj	d|dd W Y d }~d S d }~ww )	Nzs3:///chat_z	Uploaded z to DynamoDBzError processing document: %sT)exc_info)
r   r
   r   
project_idcustomer_chroma_collectionupload_to_chromadbprint	Exceptionloggingerror)r   r   r   doc_uploaderer   r   r   doc_uploader_to_chromadb   s   z-ChatDocumentUploader.doc_uploader_to_chromadb nested_pathteam_idc           
         s   | dj j d}|r| | d}t }||jj j}tdi |}t  t d}| |}t	t
dt d d fdd|D }|D ]}	|	  qNW d   d	d
iS 1 sbw   Y  d	d
iS )zIUpload the document to ChromaD only without vectorizing and storing to s3r   )r         )max_workersc                    s   g | ]
} j |qS r   )submitr   ).0r   r   executorr   r   r   
<listcomp>7   s    zDChatDocumentUploader.doc_upload_call_to_chromadb.<locals>.<listcomp>NmessagezFiles uploaded successfully.r   )r
   r   r   get_itemprojectsr   r   r   list_files_in_folderr   minos	cpu_countresult)
r   r    r!   folder_namedbr
   
s3_storagefilesfuturesfuturer   r'   r   doc_upload_call_to_chromadb"   s.   


z0ChatDocumentUploader.doc_upload_call_to_chromadbN)r   r   )	__name__
__module____qualname__r   r   r   strr   r8   r   r   r   r   r	      s    
r	   )r   r/   !utils.document_loader.DocUploaderr   utils.s3_storager   r   +services.ppt_generator.data_classes.projectr   utils.dynamo_dbr   concurrent.futuresr   utils.client_checkr   r	   r   r   r   r   <module>   s    