
    Jib                     x   d dl Z d dlZd dlm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 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 	 d dlZej:                  j=                  d      red dl m!Z  e jD                  e jF                  d      Z$ G d d      Z% G d d      Z&y# e$ r d dlZY =w xY w)    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)jsonable_encoder)remove_none_from_dict)UnprocessableEntityError)File)
FileCreate)FileIdPresignedUrl)HttpValidationError)PresignedUrl   )"FileCreateFromUrlResourceInfoValuez1..c                      e Zd ZdefdZdddddej                  e   dej                  e   dej                  e   dej                  d	e	f
d
Z
dddddej                  e   dej                  e   dej                  e   ded	ef
dZddeeeeeeddej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  ej"                  eej                  e   f      dej                  ej"                  eej                  e   f      dedej                  e   d	e	fdZddddedej                  e   dej                  e   d	e	fdZddddedej                  e   dej                  e   d	dfdZdddddedej                  e   dej                  e   dej                  e   d	ef
dZy)FilesClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     t/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/llama_cloud/resources/files/client.py__init__zFilesClient.__init__    
    -    Nexternal_file_id
project_idorganization_idr    r!   r"   upload_filereturnc          
         | j                   j                  j                  dt        j                  j                  | j                   j                          dd      t        |||d      t        i       d|i| j                   j                         d      }d|j                  cxk  rd	k  r+n n(t        j                  t        |j                               S |j                  d
k(  r1t        t        j                  t         |j                                     	 |j                         }t%        |j                  |      # t"        $ r" t%        |j                  |j&                        w xY w)
        Upload a file to S3.

        Parameters:
            - external_file_id: typing.Optional[str].

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].

            - upload_file: typing.IO.
        POST/api/v1/filesr   r#   <   paramsdatafilesheaderstimeout   ,    status_codebodyr   httpx_clientrequesturllibparseurljoinget_base_urlr	   r   get_headersr5   pydanticparse_obj_asr   jsonr
   r   r   r   textr   r    r!   r"   r#   	_response_response_jsons          r   r#   zFilesClient.upload_file#   s>   ( ((55==LL  D$8$8$E$E$G#H!JN[(%5Zdst ""% +.((446 > 

	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   D> >+E)expires_at_secondsr!   r"   rG   r9   c          
         | j                   j                  j                  dt        j                  j                  | j                   j                          dd      t        |||d      t        |      | j                   j                         d      }d|j                  cxk  rdk  r+n n(t        j                  t        |j                               S |j                  d	k(  r1t        t        j                  t         |j                                     	 |j                         }t%        |j                  |
      # t"        $ r" t%        |j                  |j&                  
      w xY w)a.  
        Create a presigned url for uploading a file.

        The presigned url is valid for a limited time period, after which it will expire.
        Be careful on accidental exposure of the presigned url, as it may allow unauthorized access to the file before the expiration.

        Parameters:
            - expires_at_seconds: typing.Optional[int].

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].

            - request: FileCreate.
        ---
        from llama_cloud import FileCreate
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.files.generate_presigned_url(
            request=FileCreate(
                name="string",
            ),
        )
        PUTr(   r)   rF   r*   r,   rA   r/   r0   r1   r2   r3   r4   r   r8   r9   r:   r;   r<   r=   r	   r   r>   r5   r?   r@   r   rA   r
   r   r   r   rB   r   rG   r!   r"   r9   rD   rE   s          r   generate_presigned_urlz"FilesClient.generate_presigned_urlL   s8   F ((55==LL  D$8$8$E$E$G#H!JN[('9hwx "'*((446 > 	
	 )''-#-(();Y^^=MNN  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   D; ;+E&r!   r"   follow_redirectsname	proxy_urlrequest_headersresource_info
verify_sslrO   rP   rQ   rR   rS   urlrT   c       	   	      t   d|i}
|t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |	t         ur|	|
d<   | j                  j                  j                  dt        j
                  j                  | j                  j                          d	d
      t        ||d      t        |
      | j                  j                         d      }d|j                  cxk  rdk  r+n n(t        j                  t        |j                               S |j                  dk(  r1t!        t        j                  t"        |j                                     	 |j                         }t'        |j                  |      # t$        $ r" t'        |j                  |j(                        w xY w)a  
        Upload a file to the project from a URL.

        If name is ommitted in the request payload, the file name will be
        extracted from the response Content-Disposition header if available
        or otherwise it will be derived from the URL path.

        If providing the name in the request payload, always suffix the
        file extension in the name if available.

        Parameters:
            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].

            - follow_redirects: typing.Optional[bool]. Whether to follow redirects when downloading the file

            - name: typing.Optional[str].

            - proxy_url: typing.Optional[str].

            - request_headers: typing.Optional[typing.Dict[str, typing.Optional[str]]].

            - resource_info: typing.Optional[typing.Dict[str, typing.Optional[FileCreateFromUrlResourceInfoValue]]].

            - url: str. URL of the file to download

            - verify_ssl: typing.Optional[bool]. Whether to verify the SSL certificate when downloading the file
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.files.upload_file_from_url(
            url="string",
        )
        rU   rO   rP   rQ   rR   rS   rT   rI   r(   api/v1/files/upload_from_urlr!   r"   r*   rJ   r1   r2   r3   r4   OMITr   r8   r9   r:   r;   r<   r=   r	   r   r>   r5   r?   r@   r   rA   r
   r   r   r   rB   r   r!   r"   rO   rP   rQ   rR   rS   rU   rT   _requestrD   rE   s                r   upload_file_from_urlz FilesClient.upload_file_from_url   s   f 384'+;H'(t#HVD $-H[!$&*9H&'$(5H_%T!%/H\"((55==LL  D$8$8$E$E$G#H!JLjk(
Wf)gh!(+((446 > 
	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   %F +F7rX   idc          	         | j                   j                  j                  dt        j                  j                  | j                   j                          dd|       t        ||d      | j                   j                         d      }d|j                  cxk  rdk  r+n n(t        j                  t        |j                               S |j                  d	k(  r1t        t        j                  t        |j                                     	 |j                         }t#        |j                  |
      # t         $ r" t#        |j                  |j$                  
      w xY w)a  
        Read File metadata objects.

        Parameters:
            - id: str.

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.files.get_file(
            id="string",
        )
        GETr(   api/v1/files/rX   r*   r,   r/   r0   r1   r2   r3   r4   r   r8   r9   r:   r;   r<   r=   r	   r>   r5   r?   r@   r   rA   r
   r   r   r   rB   r   r^   r!   r"   rD   rE   s         r   get_filezFilesClient.get_file   s0   , ((55==LL  D$8$8$E$E$G#H!Jm\^[_L`a(
Wf)gh((446 > 
	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   D3 3+Ec          	      p   | j                   j                  j                  dt        j                  j                  | j                   j                          dd|       t        ||d      | j                   j                         d      }d|j                  cxk  rdk  ry	 |j                  d
k(  r1t        t        j                  t        |j                                     	 |j                         }t!        |j                  |      # t        $ r" t!        |j                  |j"                        w xY w)a  
        Delete the file from S3.

        Parameters:
            - id: str.

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.files.delete_file(
            id="string",
        )
        DELETEr(   ra   rX   r*   rb   r1   r2   Nr3   r4   r   r8   r9   r:   r;   r<   r=   r	   r>   r5   r
   r?   r@   r   rA   r   r   rB   rd   s         r   delete_filezFilesClient.delete_file   s   , ((55==LL  D$8$8$E$E$G#H!Jm\^[_L`a(
Wf)gh((446 > 
	 )''-#- .  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   #D
 
+D5c          
         | j                   j                  j                  dt        j                  j                  | j                   j                          dd| d      t        |||d      | j                   j                         d      }d|j                  cxk  rd	k  r+n n(t        j                  t        |j                               S |j                  d
k(  r1t        t        j                  t        |j                                     	 |j                         }t#        |j                  |      # t         $ r" t#        |j                  |j$                        w xY w)a  
        Returns a presigned url to read the file content.

        Parameters:
            - id: str.

            - expires_at_seconds: typing.Optional[int].

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.files.read_file_content(
            id="string",
        )
        r`   r(   ra   /contentrF   r*   rb   r1   r2   r3   r4   r   r8   r9   r:   r;   r<   r=   r	   r>   r5   r?   r@   r   rA   r
   r   r   r   rB   r   r^   rG   r!   r"   rD   rE   s          r   read_file_contentzFilesClient.read_file_content#  s:   : ((55==LL  D$8$8$E$E$G#H!Jm\^[__gLhi('9hwx ((446 > 
	 )''-#-((y~~7GHH  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   D5 5+E )__name__
__module____qualname__r   r   typingOptionalstrIOr   r#   intr   r   rM   rZ   boolDictr   r]   re   ri   r   rn    r   r   r   r      s   .*; . 26+/04'O !//#.'O OOC(	'O
  -'O YY'O 
'OX 48+/045O #OOC05O OOC(	5O
  -5O 5O 
5Ot ,00426%)*.SWpt,0PO OOC(PO  -	PO
 !//$/PO ooc"PO ??3'PO  S&//#:N5N)OPPO v{{3Hj8k3k'lmPO PO OOD)PO 
POf >Bko%O%O&,ooc&:%OTZTcTcdgTh%O	%OP >Bko%O%O&,ooc&:%OTZTcTcdgTh%O	%OV 48+/04.O.O #OOC0	.O
 OOC(.O  -.O 
.Or   r   c                      e Zd ZdefdZdddddej                  e   dej                  e   dej                  e   dej                  d	e	f
d
Z
dddddej                  e   dej                  e   dej                  e   ded	ef
dZddeeeeeeddej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  ej"                  eej                  e   f      dej                  ej"                  eej                  e   f      dedej                  e   d	e	fdZddddedej                  e   dej                  e   d	e	fdZddddedej                  e   dej                  e   d	dfdZdddddedej                  e   dej                  e   dej                  e   d	ef
dZy)AsyncFilesClientr   c                    || _         y r   r   r   s     r   r   zAsyncFilesClient.__init__U  r   r   Nr   r    r!   r"   r#   r$   c          
        K   | j                   j                  j                  dt        j                  j                  | j                   j                          dd      t        |||d      t        i       d|i| j                   j                         d       d{   }d	|j                  cxk  rd
k  r+n n(t        j                  t        |j                               S |j                  dk(  r1t        t        j                  t         |j                                     	 |j                         }t%        |j                  |      7 # t"        $ r" t%        |j                  |j&                        w xY ww)r&   r'   r(   r)   r   r#   r*   r+   Nr1   r2   r3   r4   r7   rC   s          r   r#   zAsyncFilesClient.upload_fileX  sL    ( ..;;CCLL  D$8$8$E$E$G#H!JN[(%5Zdst ""% +.((446 D 

 

	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN'

"  	Sy'<'<9>>RR	Ss+   BE8EBE8!E
 1E8
+E55E8rF   rG   r9   c          
        K   | j                   j                  j                  dt        j                  j                  | j                   j                          dd      t        |||d      t        |      | j                   j                         d       d{   }d|j                  cxk  rd	k  r+n n(t        j                  t        |j                               S |j                  d
k(  r1t        t        j                  t         |j                                     	 |j                         }t%        |j                  |      7 # t"        $ r" t%        |j                  |j&                        w xY ww)a>  
        Create a presigned url for uploading a file.

        The presigned url is valid for a limited time period, after which it will expire.
        Be careful on accidental exposure of the presigned url, as it may allow unauthorized access to the file before the expiration.

        Parameters:
            - expires_at_seconds: typing.Optional[int].

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].

            - request: FileCreate.
        ---
        from llama_cloud import FileCreate
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.files.generate_presigned_url(
            request=FileCreate(
                name="string",
            ),
        )
        rI   r(   r)   rF   r*   rJ   Nr1   r2   r3   r4   rK   rL   s          r   rM   z'AsyncFilesClient.generate_presigned_url  sF    F ..;;CCLL  D$8$8$E$E$G#H!JN[('9hwx "'*((446 D 	
 	
	 )''-#-(();Y^^=MNN  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN%	
   	Sy'<'<9>>RR	Ss+   BE5EBE5E .E5+E22E5rN   rO   rP   rQ   rR   rS   rU   rT   c       	   	        K   d|i}
|t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |t         ur||
d<   |	t         ur|	|
d<   | j                  j                  j                  dt        j
                  j                  | j                  j                          d	d
      t        ||d      t        |
      | j                  j                         d       d{   }d|j                  cxk  rdk  r+n n(t        j                  t        |j                               S |j                  dk(  r1t!        t        j                  t"        |j                                     	 |j                         }t'        |j                  |      7 # t$        $ r" t'        |j                  |j(                        w xY ww)a%  
        Upload a file to the project from a URL.

        If name is ommitted in the request payload, the file name will be
        extracted from the response Content-Disposition header if available
        or otherwise it will be derived from the URL path.

        If providing the name in the request payload, always suffix the
        file extension in the name if available.

        Parameters:
            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].

            - follow_redirects: typing.Optional[bool]. Whether to follow redirects when downloading the file

            - name: typing.Optional[str].

            - proxy_url: typing.Optional[str].

            - request_headers: typing.Optional[typing.Dict[str, typing.Optional[str]]].

            - resource_info: typing.Optional[typing.Dict[str, typing.Optional[FileCreateFromUrlResourceInfoValue]]].

            - url: str. URL of the file to download

            - verify_ssl: typing.Optional[bool]. Whether to verify the SSL certificate when downloading the file
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.files.upload_file_from_url(
            url="string",
        )
        rU   rO   rP   rQ   rR   rS   rT   rI   r(   rW   rX   r*   rJ   Nr1   r2   r3   r4   rY   r[   s                r   r]   z%AsyncFilesClient.upload_file_from_url  s    f 384'+;H'(t#HVD $-H[!$&*9H&'$(5H_%T!%/H\"..;;CCLL  D$8$8$E$E$G#H!JLjk(
Wf)gh!(+((446 D 
 
	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN!
  	Sy'<'<9>>RR	Ss+   C'G)F*BG/F ?G+GGrX   r^   c          	        K   | j                   j                  j                  dt        j                  j                  | j                   j                          dd|       t        ||d      | j                   j                         d       d{   }d|j                  cxk  rd	k  r+n n(t        j                  t        |j                               S |j                  d
k(  r1t        t        j                  t        |j                                     	 |j                         }t#        |j                  |      7 # t         $ r" t#        |j                  |j$                        w xY ww)a  
        Read File metadata objects.

        Parameters:
            - id: str.

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.files.get_file(
            id="string",
        )
        r`   r(   ra   rX   r*   rb   Nr1   r2   r3   r4   rc   rd   s         r   re   zAsyncFilesClient.get_file
  s>    , ..;;CCLL  D$8$8$E$E$G#H!Jm\^[_L`a(
Wf)gh((446 D 
 
	 )''-#-((y~~/?@@  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN
  	Sy'<'<9>>RR	Ss+   BE-D=BE-D? &E-?+E**E-c          	        K   | j                   j                  j                  dt        j                  j                  | j                   j                          dd|       t        ||d      | j                   j                         d       d{   }d|j                  cxk  rd	k  ry |j                  d
k(  r1t        t        j                  t        |j                                     	 |j                         }t!        |j                  |      7 # t        $ r" t!        |j                  |j"                        w xY ww)a  
        Delete the file from S3.

        Parameters:
            - id: str.

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.files.delete_file(
            id="string",
        )
        rg   r(   ra   rX   r*   rb   Nr1   r2   r3   r4   rh   rd   s         r   ri   zAsyncFilesClient.delete_file1  s,    , ..;;CCLL  D$8$8$E$E$G#H!Jm\^[_L`a(
Wf)gh((446 D 
 
	 )''-#- .  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN
  	Sy'<'<9>>RR	Ss+   BEDAE-D =E+EEc          
        K   | j                   j                  j                  dt        j                  j                  | j                   j                          dd| d      t        |||d      | j                   j                         d       d{   }d	|j                  cxk  rd
k  r+n n(t        j                  t        |j                               S |j                  dk(  r1t        t        j                  t        |j                                     	 |j                         }t#        |j                  |      7 # t         $ r" t#        |j                  |j$                        w xY ww)a  
        Returns a presigned url to read the file content.

        Parameters:
            - id: str.

            - expires_at_seconds: typing.Optional[int].

            - project_id: typing.Optional[str].

            - organization_id: typing.Optional[str].
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.files.read_file_content(
            id="string",
        )
        r`   r(   ra   rk   rF   r*   rb   Nr1   r2   r3   r4   rl   rm   s          r   rn   z"AsyncFilesClient.read_file_contentX  sH    : ..;;CCLL  D$8$8$E$E$G#H!Jm\^[__gLhi('9hwx ((446 D 
 
	 )''-#-((y~~7GHH  C'*8+@+@ATV_VdVdVf+ghh	S&^^-N 9#8#8~NN#
  	Sy'<'<9>>RR	Ss+   BE/D?BE/E (E/+E,,E/)ro   rp   rq   r   r   rr   rs   rt   ru   r   r#   rv   r   r   rM   rZ   rw   rx   r   r]   re   ri   r   rn   ry   r   r   r{   r{   T  s   .*< . 26+/04'O !//#.'O OOC(	'O
  -'O YY'O 
'OX 48+/045O #OOC05O OOC(	5O
  -5O 5O 
5Ot ,00426%)*.SWpt,0PO OOC(PO  -	PO
 !//$/PO ooc"PO ??3'PO  S&//#:N5N)OPPO v{{3Hj8k3k'lmPO PO OOD)PO 
POf >Bko%O%O&,ooc&:%OTZTcTcdgTh%O	%OP >Bko%O%O&,ooc&:%OTZTcTcdgTh%O	%OV 48+/04.O.O #OOC0	.O
 OOC(.O  -.O 
.Or   r{   )'rr   urllib.parser:   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.jsonable_encoderr   core.remove_none_from_dictr	   !errors.unprocessable_entity_errorr
   
types.filer   types.file_creater   types.file_id_presigned_urlr   types.http_validation_errorr   types.presigned_urlr   .types.file_create_from_url_resource_info_valuer   r?   __version__
startswithImportErrorpydantic.v1v1castAnyrZ   r   r{   ry   r   r   <module>r      s      ( & H 5 ? I  + = > / ^&&t,"
 v{{6::s#rO rOj	rO rOy	  s   'B- -	B98B9