o
    |!g*!                    @   s^  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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' zd dl(Z(e(j)*dre+d dl,m-Z( W n e+y   d dl(Z(Y nw e .e j/dZ0G dd dZ1G dd dZ2dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)jsonable_encoder)remove_none_from_dict)UnprocessableEntityError)HttpValidationError)!LlamaParseSupportedFileExtensions)ParserLanguages)ParsingHistoryItem)
ParsingJob)ParsingJobJsonResult)ParsingJobMarkdownResult)ParsingJobStructuredResult)ParsingJobTextResult)ParsingMode)ParsingUsage)PresignedUrlz1..c                   @     e Zd ZdefddZdededdfdd	Zdeje	 fd
dZ
ddeeddeje deje deje dededededededeje dededededededef"ddZddeeeddeje deje deje d ed!ed"ed#ed$ed%ed&ed'ed(ed)ed*ed+ed,ed-ed.ed/ed0ed1eded2ed3ed4ed5ed6ed7edededededed8eje d9edeje d:ededed;ed<ed=ed>ed?ed@edAedBedCedDededEedFedGededHeje dIedJedKedededLedMedNedOedPedQedRedSedTedUedVedWedXedYedZed[ed\ed]edefd^d_Zdd`deje defdadbZdedefdcddZdedejfdedfZdd`dedeje defdgdhZdedejfdidjZdd`dedeje defdkdlZdedejfdmdnZdedejfdodpZ dd`dedeje de!fdqdrZ"dedejfdsdtZ#dd`dedeje de$fdudvZ%dedejfdwdxZ&deje' fdydzZ(ded{ede)fd|d}Z*dS )~ParsingClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   f/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/llama_cloud/resources/parsing/client.py__init__&      
zParsingClient.__init__job_idnamereturnNc              	   C   s   | j jjdtj| j   dd| d| | j  dd}d|j  kr+dk r,d	S  |jd
kr;t	t
t| z| }W n tyP   t|j|jdw t|j|d)a`  
        Get a job by id

        Parameters:
            - job_id: str.

            - name: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_image_result(
            job_id="string",
            name="string",
        )
        GET/api/v1/parsing/job//result/image/<   headerstimeout   ,  N  status_codebodyr   httpx_clientrequesturllibparseurljoinget_base_urlget_headersr2   r	   pydanticparse_obj_asr
   jsonr   r   textr   r#   r$   	_response_response_jsonr   r   r    get_job_image_result)   s&   
z"ParsingClient.get_job_image_resultc                 C   s   | j jjdtj| j   dd| j  dd}d|j  kr$dk r1n nt	
tjt | S z| }W n tyF   t|j|jdw t|j|d)	z
        Get a list of supported file extensions

        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_supported_file_extensions()
        r&   r'   (api/v1/parsing/supported_file_extensionsr*   r+   r.   r/   r1   r   r5   r6   r7   r8   r9   r:   r;   r2   r<   r=   typingListr   r>   r   r   r?   r   rA   rB   r   r   r    get_supported_file_extensionsN   s   z+ParsingClient.get_supported_file_extensionsorganization_id
project_idfile	max_pagesrK   rL   rM   do_not_cache
http_proxyinput_s_3_pathinput_s_3_region	input_urlinvalidate_cacherN   output_s_3_path_prefixoutput_s_3_regiontarget_pageswebhook_urljob_timeout_in_seconds*job_timeout_extra_time_per_page_in_secondsc                C   s  ||||||	||||||d}|t ur||d< |
t ur|
|d< | jjjdtj| j  ddt||dt	|| j
 dd	}d
|j  krLdk rVn ntt| S |jdkrettt| z| }W n tyz   t|j|jdw t|j|d)  
        Parameters:
            - organization_id: typing.Optional[str].

            - project_id: typing.Optional[str].

            - file: typing.Optional[str].

            - do_not_cache: bool.

            - http_proxy: str.

            - input_s_3_path: str.

            - input_s_3_region: str.

            - input_url: str.

            - invalidate_cache: bool.

            - max_pages: typing.Optional[int].

            - output_s_3_path_prefix: str.

            - output_s_3_region: str.

            - target_pages: str.

            - webhook_url: str.

            - job_timeout_in_seconds: float.

            - job_timeout_extra_time_per_page_in_seconds: float.
        rO   rP   input_s3_pathinput_s3_regionrS   rT   output_s3_path_prefixoutput_s3_regionrW   rX   rY   rZ   rM   rN   POSTr'   api/v1/parsing/screenshotrK   rL   r*   paramsr>   r,   r-   r.   r/   r0   r1   OMITr   r5   r6   r7   r8   r9   r:   r   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   rK   rL   rM   rO   rP   rQ   rR   rS   rT   rN   rU   rV   rW   rX   rY   rZ   _requestrA   rB   r   r   r    
screenshoth   sF   7
zParsingClient.screenshotrK   rL   rM   rN   
parse_modeadaptive_long_tableannotate_links	auto_mode"auto_mode_trigger_on_image_in_page"auto_mode_trigger_on_table_in_page!auto_mode_trigger_on_text_in_page#auto_mode_trigger_on_regexp_in_pageazure_openai_api_versionazure_openai_deployment_nameazure_openai_endpointazure_openai_keybbox_bottom	bbox_left
bbox_rightbbox_topdisable_ocrdisable_reconstructiondisable_image_extractiondo_not_unroll_columnsextract_chartsguess_xlsx_sheet_namehtml_make_all_elements_visiblehtml_remove_fixed_elementshtml_remove_navigation_elementslanguageextract_layoutoutput_pdf_of_documentpage_prefixpage_separatorpage_suffix&preserve_layout_alignment_across_pagesskip_diagonal_textspreadsheet_extract_sub_tablesstructured_outputstructured_output_json_schema"structured_output_json_schema_nametake_screenshotvendor_multimodal_api_keyvendor_multimodal_model_namemodelrl   system_promptsystem_prompt_appenduser_promptstrict_mode_image_extractionstrict_mode_image_ocrstrict_mode_reconstructionstrict_mode_buggy_font-ignore_document_elements_for_layout_detectionoutput_tables_as_htmluse_vendor_multimodal_modelbounding_boxgpt_4_o_modegpt_4_o_api_key#complemental_formatting_instructioncontent_guideline_instructionpremium_modeis_formatting_instructioncontinuous_modeparsing_instruction	fast_modeformatting_instructionc       N   R      C   s  i d|d|d|d|d|d|	d|
d|d	|d
|d|d|d|d|d|d|d|i d|d|d|d|d|d|d|d|d|d|d|d| d|!d|"d |#d!|%d"|&i d#|'d$|(d%|)d&|*d'|+d(|,d)|-d*|.d+|/d,|0d-|1d.|2d/|3d0|4d1|5d2|6d3|8i d4|9d5|:d6|;d7|<d8|=d9|>d:|?d;|@d<|Ad=|Bd>|Cd?|Dd@|EdA|FdB|GdC|HdD|I|J|K|L|M|NdE}O|t ur||OdF< |$t ur|$|OdG< |7t ur|7|OdH< | jjjdItj| j  dJdKt||dLt	|O| j
 dMdN}PdO|Pj  kr#dPk r-n ntt|P S |PjdQkr=ttt|P z|P }QW n tyS   t|Pj|PjdRw t|Pj|QdR)S  
        Upload a file to s3 and create a job. return a job id

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

            - project_id: typing.Optional[str].

            - file: typing.Optional[str].

            - adaptive_long_table: bool.

            - annotate_links: bool.

            - auto_mode: bool.

            - auto_mode_trigger_on_image_in_page: bool.

            - auto_mode_trigger_on_table_in_page: bool.

            - auto_mode_trigger_on_text_in_page: str.

            - auto_mode_trigger_on_regexp_in_page: str.

            - azure_openai_api_version: str.

            - azure_openai_deployment_name: str.

            - azure_openai_endpoint: str.

            - azure_openai_key: str.

            - bbox_bottom: float.

            - bbox_left: float.

            - bbox_right: float.

            - bbox_top: float.

            - disable_ocr: bool.

            - disable_reconstruction: bool.

            - disable_image_extraction: bool.

            - do_not_cache: bool.

            - do_not_unroll_columns: bool.

            - extract_charts: bool.

            - guess_xlsx_sheet_name: bool.

            - html_make_all_elements_visible: bool.

            - html_remove_fixed_elements: bool.

            - html_remove_navigation_elements: bool.

            - http_proxy: str.

            - input_s_3_path: str.

            - input_s_3_region: str.

            - input_url: str.

            - invalidate_cache: bool.

            - language: typing.List[ParserLanguages].

            - extract_layout: bool.

            - max_pages: typing.Optional[int].

            - output_pdf_of_document: bool.

            - output_s_3_path_prefix: str.

            - output_s_3_region: str.

            - page_prefix: str.

            - page_separator: str.

            - page_suffix: str.

            - preserve_layout_alignment_across_pages: bool.

            - skip_diagonal_text: bool.

            - spreadsheet_extract_sub_tables: bool.

            - structured_output: bool.

            - structured_output_json_schema: str.

            - structured_output_json_schema_name: str.

            - take_screenshot: bool.

            - target_pages: str.

            - vendor_multimodal_api_key: str.

            - vendor_multimodal_model_name: str.

            - model: str.

            - webhook_url: str.

            - parse_mode: typing.Optional[ParsingMode].

            - system_prompt: str.

            - system_prompt_append: str.

            - user_prompt: str.

            - job_timeout_in_seconds: float.

            - job_timeout_extra_time_per_page_in_seconds: float.

            - strict_mode_image_extraction: bool.

            - strict_mode_image_ocr: bool.

            - strict_mode_reconstruction: bool.

            - strict_mode_buggy_font: bool.

            - ignore_document_elements_for_layout_detection: bool.

            - output_tables_as_html: bool.

            - use_vendor_multimodal_model: bool.

            - bounding_box: str.

            - gpt_4_o_mode: bool.

            - gpt_4_o_api_key: str.

            - complemental_formatting_instruction: str.

            - content_guideline_instruction: str.

            - premium_mode: bool.

            - is_formatting_instruction: bool.

            - continuous_mode: bool.

            - parsing_instruction: str.

            - fast_mode: bool.

            - formatting_instruction: str.
        rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rO   r   r   r   r   r   r   rP   r]   r^   rS   rT   r   r   r   r_   r`   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   rX   r   r   r   rY   rZ   r   r   r   r   r   output_tables_as_HTMLr   r   
gpt4o_modegpt4o_api_keyr   r   r   r   r   r   r   r   rM   rN   rl   ra   r'   api/v1/parsing/uploadrc   r*   rd   r.   r/   r0   r1   rf   Rr   rK   rL   rM   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rO   r   r   r   r   r   r   rP   rQ   rR   rS   rT   r   r   rN   r   rU   rV   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   rX   rl   r   r   r   rY   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   rA   rB   r   r   r    upload_file   sP   s	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEKzParsingClient.upload_filerK   c                C   s   | j jjdtj| j   ddtd|i| j  dd}d|j	  kr)dk r3n nt
t| S |j	d	krBtt
t| z| }W n tyW   t|j	|jd
w t|j	|d
)a  
        DEPRECATED: use either /organizations/{organization_id}/usage or /projects/{project_id}/usage instead
        Get parsing usage for user

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

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.usage()
        r&   r'   api/v1/parsing/usagerK   r*   re   r,   r-   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   rK   rA   rB   r   r   r    usage  s"   

zParsingClient.usagec                 C   s   | j jjdtj| j   dd| | j  dd}d|j  kr'dk r1n nt	
t| S |jdkr@tt	
t| z| }W n tyU   t|j|jd	w t|j|d	)
a  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job(
            job_id="string",
        )
        r&   r'   r(   r*   r+   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r#   rA   rB   r   r   r    get_job7  s    
zParsingClient.get_jobc                 C      | j jjdtj| j   dd| d| j  dd}d|j  kr(dk r3n n	t	
tj| S |jd	krBtt	
t| z| }W n tyW   t|j|jd
w t|j|d
)a.  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_parsing_job_details(
            job_id="string",
        )
        r&   r'   r(   /detailsr*   r+   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r;   r2   r<   r=   rF   Anyr>   r	   r
   r   r   r?   r   r   r   r    get_parsing_job_detailsW  s     
z%ParsingClient.get_parsing_job_detailsc                C      | j jjdtj| j   dd| dtd|i| j  dd}d|j	  kr-d	k r7n nt
t| S |j	d
krFtt
t| z| }W n ty[   t|j	|jdw t|j	|d)a`  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_text_result(
            job_id="string",
        )
        r&   r'   r(   /result/textrK   r*   r   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r#   rK   rA   rB   r   r   r    get_job_text_resultw  "    

z!ParsingClient.get_job_text_resultc                 C   r   )a.  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_raw_text_result(
            job_id="string",
        )
        r&   r'   r(   /result/raw/pdfr*   r+   r.   r/   r0   r1   r   r   r   r   r    get_job_raw_text_result  $   
z%ParsingClient.get_job_raw_text_resultc                C   r   )af  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_structured_result(
            job_id="string",
        )
        r&   r'   r(   /result/structuredrK   r*   r   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r   r   r    get_job_structured_result  s&   
	
z'ParsingClient.get_job_structured_resultc                 C   r   )a4  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_raw_structured_result(
            job_id="string",
        )
        r&   r'   r(   /result/raw/structuredr*   r+   r.   r/   r0   r1   r   r   r   r   r    get_job_raw_structured_result  r   z+ParsingClient.get_job_raw_structured_resultc                 C   r   )a.  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_raw_xlsx_result(
            job_id="string",
        )
        r&   r'   r(   /result/raw/xlsxr*   r+   r.   r/   r0   r1   r   r   r   r   r    get_job_raw_xlsx_result  r   z%ParsingClient.get_job_raw_xlsx_resultc                C   r   )a[  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_result(
            job_id="string",
        )
        r&   r'   r(   /result/markdownrK   r*   r   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r   r   r    get_job_result'  s&   
	
zParsingClient.get_job_resultc                 C   r   )a,  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_raw_md_result(
            job_id="string",
        )
        r&   r'   r(   /result/raw/markdownr*   r+   r.   r/   r0   r1   r   r   r   r   r    get_job_raw_md_resultL  r   z#ParsingClient.get_job_raw_md_resultc                C   r   )a`  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_json_result(
            job_id="string",
        )
        r&   r'   r(   /result/jsonrK   r*   r   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r   r   r    get_job_json_resultn  r   z!ParsingClient.get_job_json_resultc                 C   r   )a.  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_job_json_raw_result(
            job_id="string",
        )
        r&   r'   r(   /result/raw/jsonr*   r+   r.   r/   r0   r1   r   r   r   r   r    get_job_json_raw_result  r   z%ParsingClient.get_job_json_raw_resultc                 C   s   | j jjdtj| j   dd| j  dd}d|j  kr$dk r1n nt	
tjt | S |jdkr@tt	
t| z| }W n tyU   t|j|jd	w t|j|d	)
z
        Get parsing history for user

        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.get_parsing_history_result()
        r&   r'   api/v1/parsing/historyr*   r+   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r;   r2   r<   r=   rF   rG   r   r>   r	   r
   r   r   r?   rH   r   r   r    get_parsing_history_result  s    
z(ParsingClient.get_parsing_history_resultfilenamec              	   C   s   | j jjdtj| j   dd| d| | j  dd}d|j  kr*dk r4n nt	
t| S |jd	krCtt	
t| z| }W n tyX   t|j|jd
w t|j|d
)a}  
        Generate a presigned URL for a job

        Parameters:
            - job_id: str.

            - filename: str.
        ---
        from llama_cloud.client import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.parsing.generate_presigned_url(
            job_id="string",
            filename="string",
        )
        r&   r'   r(   /read/r*   r+   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r;   r2   r<   r=   r   r>   r	   r
   r   r   r?   r   r#   r   rA   rB   r   r   r    generate_presigned_url  s$   
z$ParsingClient.generate_presigned_url)+__name__
__module____qualname__r   r!   strrC   rF   rG   r   rI   rg   Optionalboolintfloatr   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   %   s   %	

]!	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ
  W  " ##
'"""%""#"r   c                   @   r   )~AsyncParsingClientr   c                C   r   r   r   r   r   r   r    r!     r"   zAsyncParsingClient.__init__r#   r$   r%   Nc              	      s   | j jjdtj| j   dd| d| | j  ddI dH }d|j  kr/d	k r0dS  |jd
kr?t	t
t| z| }W n tyT   t|j|jdw t|j|d)ap  
        Get a job by id

        Parameters:
            - job_id: str.

            - name: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_image_result(
            job_id="string",
            name="string",
        )
        r&   r'   r(   r)   r*   r+   Nr.   r/   r0   r1   r4   r@   r   r   r    rC     s(   
z'AsyncParsingClient.get_job_image_resultc                    s   | j jjdtj| j   dd| j  ddI dH }d|j  kr(dk r5n nt	
tjt | S z| }W n tyJ   t|j|jd	w t|j|d	)
a  
        Get a list of supported file extensions

        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_supported_file_extensions()
        r&   r'   rD   r*   r+   Nr.   r/   r1   rE   rH   r   r   r    rI     s   z0AsyncParsingClient.get_supported_file_extensionsrJ   rK   rL   rM   rO   rP   rQ   rR   rS   rT   rN   rU   rV   rW   rX   rY   rZ   c                   s  ||||||	||||||d}|t ur||d< |
t ur |
|d< | jjjdtj| j  ddt||dt	|| j
 dd	I d
H }d|j  krPdk rZn ntt| S |jdkrittt| z| }W n ty~   t|j|jdw t|j|d)r[   r\   rM   rN   ra   r'   rb   rc   r*   rd   Nr.   r/   r0   r1   rf   rh   r   r   r    rj   8  sH   7
zAsyncParsingClient.screenshotrk   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c       N   R         s  i d|d|d|d|d|d|	d|
d|d	|d
|d|d|d|d|d|d|d|i d|d|d|d|d|d|d|d|d|d|d|d| d|!d|"d |#d!|%d"|&i d#|'d$|(d%|)d&|*d'|+d(|,d)|-d*|.d+|/d,|0d-|1d.|2d/|3d0|4d1|5d2|6d3|8i d4|9d5|:d6|;d7|<d8|=d9|>d:|?d;|@d<|Ad=|Bd>|Cd?|Dd@|EdA|FdB|GdC|HdD|I|J|K|L|M|NdE}O|t ur||OdF< |$t ur|$|OdG< |7t ur|7|OdH< | jjjdItj| j  dJdKt||dLt	|O| j
 dMdNI dOH }PdP|Pj  kr'dQk r1n ntt|P S |PjdRkrAttt|P z|P }QW n tyW   t|Pj|PjdSw t|Pj|QdS)Tr   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rO   r   r   r   r   r   r   rP   r]   r^   rS   rT   r   r   r   r_   r`   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   rX   r   r   r   rY   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   rN   rl   ra   r'   r   rc   r*   rd   Nr.   r/   r0   r1   rf   r   r   r   r    r     sR   s	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEKzAsyncParsingClient.upload_filer   c                   s   | j jjdtj| j   ddtd|i| j  ddI dH }d|j	  kr-d	k r7n nt
t| S |j	d
krFtt
t| z| }W n ty[   t|j	|jdw t|j	|d)a  
        DEPRECATED: use either /organizations/{organization_id}/usage or /projects/{project_id}/usage instead
        Get parsing usage for user

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

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.usage()
        r&   r'   r   rK   r*   r   Nr.   r/   r0   r1   r   r   r   r   r    r     s$   

zAsyncParsingClient.usagec                    s   | j jjdtj| j   dd| | j  ddI dH }d|j  kr+dk r5n nt	
t| S |jd	krDtt	
t| z| }W n tyY   t|j|jd
w t|j|d
)a.  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job(
            job_id="string",
        )
        r&   r'   r(   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r     s"   
zAsyncParsingClient.get_jobc                       | j jjdtj| j   dd| d| j  ddI dH }d|j  kr,d	k r7n n	t	
tj| S |jd
krFtt	
t| z| }W n ty[   t|j|jdw t|j|d)a>  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_parsing_job_details(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r   '  s"    
z*AsyncParsingClient.get_parsing_job_detailsc                      | j jjdtj| j   dd| dtd|i| j  ddI dH }d	|j	  kr1d
k r;n nt
t| S |j	dkrJtt
t| z| }W n ty_   t|j	|jdw t|j	|d)ap  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_text_result(
            job_id="string",
        )
        r&   r'   r(   r   rK   r*   r   Nr.   r/   r0   r1   r   r   r   r   r    r   G  $    

z&AsyncParsingClient.get_job_text_resultc                    r   )a>  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_raw_text_result(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r   l  &   
z*AsyncParsingClient.get_job_raw_text_resultc                   r   )av  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_structured_result(
            job_id="string",
        )
        r&   r'   r(   r   rK   r*   r   Nr.   r/   r0   r1   r   r   r   r   r    r     (   
	
z,AsyncParsingClient.get_job_structured_resultc                    r   )aD  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_raw_structured_result(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r     r   z0AsyncParsingClient.get_job_raw_structured_resultc                    r   )a>  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_raw_xlsx_result(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r     r   z*AsyncParsingClient.get_job_raw_xlsx_resultc                   r   )ak  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_result(
            job_id="string",
        )
        r&   r'   r(   r   rK   r*   r   Nr.   r/   r0   r1   r   r   r   r   r    r     r   z!AsyncParsingClient.get_job_resultc                    r   )a<  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_raw_md_result(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r      r   z(AsyncParsingClient.get_job_raw_md_resultc                   r   )ap  
        Get a job by id

        Parameters:
            - job_id: str.

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

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_json_result(
            job_id="string",
        )
        r&   r'   r(   r   rK   r*   r   Nr.   r/   r0   r1   r   r   r   r   r    r   B  r   z&AsyncParsingClient.get_job_json_resultc                    r   )a>  
        Get a job by id

        Parameters:
            - job_id: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_job_json_raw_result(
            job_id="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r   g  r   z*AsyncParsingClient.get_job_json_raw_resultc                    s   | j jjdtj| j   dd| j  ddI dH }d|j  kr(dk r5n nt	
tjt | S |jd	krDtt	
t| z| }W n tyY   t|j|jd
w t|j|d
)z
        Get parsing history for user

        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.get_parsing_history_result()
        r&   r'   r   r*   r+   Nr.   r/   r0   r1   r   rH   r   r   r    r     s"   
z-AsyncParsingClient.get_parsing_history_resultr   c              	      s   | j jjdtj| j   dd| d| | j  ddI dH }d|j  kr.d	k r8n nt	
t| S |jd
krGtt	
t| z| }W n ty\   t|j|jdw t|j|d)a  
        Generate a presigned URL for a job

        Parameters:
            - job_id: str.

            - filename: str.
        ---
        from llama_cloud.client import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )
        await client.parsing.generate_presigned_url(
            job_id="string",
            filename="string",
        )
        r&   r'   r(   r   r*   r+   Nr.   r/   r0   r1   r   r   r   r   r    r     s&   
z)AsyncParsingClient.generate_presigned_url)+r   r   r   r   r!   r   rC   rF   rG   r   rI   rg   r   r   r   r   r   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r     s   %	

]!	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ
  W  !
%#
'"#
'#
%"r   )3rF   urllib.parser7   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.jsonable_encoderr   core.remove_none_from_dictr   !errors.unprocessable_entity_errorr	   types.http_validation_errorr
   +types.llama_parse_supported_file_extensionsr   types.parser_languagesr   types.parsing_history_itemr   types.parsing_jobr   types.parsing_job_json_resultr   !types.parsing_job_markdown_resultr   #types.parsing_job_structured_resultr   types.parsing_job_text_resultr   types.parsing_moder   types.parsing_usager   types.presigned_urlr   r<   __version__
startswithImportErrorpydantic.v1v1castr   rg   r   r   r   r   r   r    <module>   sL          W