
    i(                       S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJrJrJr  S SKJrJrJrJrJrJrJr  S SKJr  S SKrS S	KJr  S S
KJrJ r   S SK!J"r"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)  S SK*J+r+  S SK,J-r-  S SK.J/r/  S SK0J1r1  S SK2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<  \\=\>\4   r?Sr@SrASrBSrCS\=S\\=   S\\=   S\=4S jrD " S S\E5      rF " S S\=\
5      rG " S  S!\)5      rHg)"    N)asynccontextmanager)deepcopy)Enum)BufferedIOBase)PathPurePathPurePosixPath)AnyAsyncGeneratorDictListOptionalTupleUnion)urlparse)AbstractFileSystem)asyncio_runrun_jobs)FieldPrivateAttrfield_validatormodel_validator)DEFAULT_BASE_URL)BasePydanticReader)get_default_fs)Document)check_extra_params)	JobResult)
SUPPORTED_FILE_TYPES
ResultTypeParsingModeFailedPageModeexpand_target_pagesnest_asyncio_errnest_asyncio_msgmake_api_requestpartition_pages extract_tables_from_json_resultsz
---
z./api/parsing/job/{job_id}/result/{result_type}z/api/parsing/job/{job_id}z/api/parsing/uploadbase_urlorganization_id
project_idreturnc           
          0 nU(       a  XS'   U(       a  X#S'   U(       a?  U S-   SR                  UR                  5        VVs/ s H  u  pEU SU 3PM     snn5      -   $ U $ s  snnf )Nr*   r+   ?&=)joinitems)r)   r*   r+   query_paramskvs         Y/home/james-whalen/.local/lib/python3.13/site-packages/llama_cloud_services/parse/base.py	build_urlr7   7   sl     L*9&'%/\"#~ASASAU)VAUQCq*AU)V WWWO *Ws   A!c            
       z   ^  \ rS rSrSr  SS\S\S\\   S\\   4U 4S jjjr\S\	\\
4   S	S 4S
 j5       rSrU =r$ )JobFailedExceptionF   zParse job failed exception.job_idstatus
error_codeerror_messagec           	         > SU SU SU=(       d    S SU=(       d    S 3n[         TU ]  U5        Xl        X l        X0l        X@l        g )NzJob ID: z failed with status: z, Error code: zNo error code foundz, Error message: zNo error message found)super__init__r;   r<   r=   r>   )selfr;   r<   r=   r>   exception_str	__class__s         r6   rA   JobFailedException.__init__I   se     vh3F8 <%>)>? @+G/GHJ 	
 	'$*    result_jsonr,   c                 h    US   nUS   nUR                  S5      nUR                  S5      nU " X#XES9$ )Nidr<   r=   r>   )r=   r>   )get)clsrG   r;   r<   r=   r>   s         r6   from_resultJobFailedException.from_result[   s?    T"X& __\2
#86jVVrF   )r=   r>   r;   r<   NN)__name__
__module____qualname____firstlineno____doc__strr   rA   classmethodr   r
   rL   __static_attributes____classcell__)rD   s   @r6   r9   r9   F   su    % %)'+++ + SM	+
  }+ +$ Wd38n W9M W WrF   r9   c                   $    \ rS rSrSrSrSrSrSrg)BackoffPatternd   zBackoff pattern for polling.constantlinearexponential N)	rO   rP   rQ   rR   rS   CONSTANTLINEAREXPONENTIALrV   r^   rF   r6   rY   rY   d   s    &HFKrF   rY   c                   8   \ rS rSr% Sr\" SSSS9r\\S'   \" \	SS	9r
\\S
'   \" SSS	9r\\   \S'   \" SSS	9r\\   \S'   \" SSS	9r\\S'   \" \R"                  SS	9r\\S'   \" SSS	9r\\S'   \" SSS	9r\\R,                     \S'   \" SSS	9r\\S'   \" SSS	9r\\S'   \" SS S!S"S#9r\\S$'   \" \R8                  S%S	9r\\S&'   \" SS'S	9r\\S('   \" SS)S	9r\\S*'   \" SS+S	9r \\S,'   \" S-S.S	9r!\\   \S/'   \" S-S0S	9r"\\   \S1'   \" S-S2S	9r#\\   \S3'   \" SS4S	9r$\\   \S5'   \" S-S6S	9r%\\   \S7'   \" S-S8S	9r&\\   \S9'   \" SS:S	9r'\\   \S;'   \" SS<S	9r(\\   \S='   \" SS>S	9r)\\   \S?'   \" SS@S	9r*\\   \SA'   \" SSBS	9r+\\   \SC'   \" SSDS	9r,\\   \SE'   \" SSFS	9r-\\.   \SG'   \" SSHS	9r/\\.   \SI'   \" SSJS	9r0\\.   \SK'   \" SSLS	9r1\\.   \SM'   \" S-SNS	9r2\\   \SO'   \" S-SPS	9r3\\   \SQ'   \" S-SRS	9r4\\   \SS'   \" S-STS	9r5\\   \SU'   \" S-SVS	9r6\\   \SW'   \" S-SXS	9r7\\   \SY'   \" S-SZS	9r8\\   \S['   \" S-S\S	9r9\\   \S]'   \" S-S^S	9r:\\   \S_'   \" S-S`S	9r;\\   \Sa'   \" S-SbS	9r<\\   \Sc'   \" S-SdS	9r=\\   \Se'   \" S-SfS	9r>\\   \Sg'   \" S-ShS	9r?\\   \Si'   \" SSjS	9r@\\   \Sk'   \" S-SlS	9rA\\   \Sm'   \" SSnS	9rB\\   \So'   \" S-SpS	9rC\\   \Sq'   \" SSrS	9rD\\.   \Ss'   \" SStS	9rE\\.   \Su'   \" SvSwS	9rF\\   \Sx'   \" SSyS	9rG\\   \Sz'   \" SS{S	9rH\\   \S|'   \" S-S}S	9rI\\   \S~'   \" S-SS	9rJ\\   \S'   \" SSS	9rK\\   \S'   \" SSS	9rL\\   \S'   \" S-SS	9rM\\   \S'   \" S-SS	9rN\\   \S'   \" SSS	9rO\\.   \S'   \" SSS	9rP\\   \S'   \" SSS	9rQ\\   \S'   \" SSS	9rR\\   \S'   \" SSS	9rS\\T\U\4      \S'   \" S-SS	9rV\\   \S'   \" SSS	9rW\\   \S'   \" S-SS	9rX\\   \S'   \" S-SS	9rY\\   \S'   \" SSS	9rZ\\[   \S'   \" SSS	9r\\\   \S'   \" SSS	9r]\\   \S'   \" S-SS	9r^\\   \S'   \" S-SS	9r_\\   \S'   \" S-SS	9r`\\   \S'   \" S-SS	9ra\\   \S'   \" S-SS	9rb\\   \S'   \" S-SS	9rc\\   \S'   \" S-SS	9rd\\   \S'   \" SSS	9re\\   \S'   \" SSS	9rf\\   \S'   \" SSS	9rg\\   \S'   \" SSS	9rh\\   \S'   \" S-SS	9ri\\   \S'   \" SSS	9rj\\   \S'   \" SSS	9rk\\   \S'   \" SSS	9rl\\   \S'   \" SSS	9rm\\   \S'   \" SSS	9rn\\   \S'   \" SSS	9ro\\   \S'   \" SSS	9rp\\   \S'   \" S-SS	9rq\\   \S'   \" S-SS	9rr\\   \S'   \" SSS	9rs\\   \S'   \" SSS	9rt\\   \S'   \" SSS	9ru\\   \S'   \" SSS	9rv\\   \S'   \" SSS	9rw\\   \S'   \" SSS	9rx\\   \S'   \" SSS	9ry\\   \S'   \" SSS	9rz\\   \S'   \" S-SS	9r{\\   \S'   \" SSS	9r|\\   \S'   \" S-SS	9r}\\   \S'   \" SSS	9r~\\   \S'   \" S-SS	9r\\   \S'   \" SS9\S\\\4   S\\\4   4S j5       5       r\" SSSS9\S\S\4S j5       5       r\" S
SSS9\S\S\4S j5       5       r\" SS-S9r\T\R,                  S4   \S'   \S\R,                  4S j5       r\S\\R,                  S4   4S j5       rS\S\4S jrS\S\4S jr   GS S\S\\   S\\   S\\   S\4
S jjrS\.S\.4S jr GS!S\S&\S,\S\\\4   4S jjr    GS"S\S\\   S\\   S&\\   S$\\   S\\\\\\4   4      4S jjr   GS S\S\\   S\\   S&\\   S\S\\\\\4   4   4GS  jjr    GS"S\S\\   S\\   S&\\   S$\\   S\\\\\\4   4      4GS jjr    GS#S\S\\   S\\   S,\S$\\   S\\   4GS jjr  GS$S\T\\   \4   S\\   S\\   S\\   4GS jjr  GS$S\T\\   \4   S\\   S\\   S\\   4GS jjr   GS S\GS\S\\   S\\   S$\\   S\\   4GS jjr  GS$S\T\\   \4   S\\   S\\   S\T\GS   GS4   4GS jjr  GS$S\T\\   \4   S\\   S\\   S\T\GS   GS4   4GS	 jjr  GS$S\S\\   S$\\   S\\   4GS
 jjr GS%S\T\\   \4   S\\   S\\   4GS jjr GS%S\T\\   \4   S\\   S\\   4GS jjr GS%S\T\\   \4   S\\   S\\   4GS jjrGS\\   GS\GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   GS\S\\   4GS jrGS\\   S\\   4GS jrS\T\\\   4   S\T\\\   4   4GS jrS\T\\\   4   S\T\\\   4   4GS jrGSrg(&  
LlamaParsel   zA smart-parser for files. z#The API key for the LlamaParse API.T)defaultdescriptionvalidate_defaultapi_keyz&The base URL of the Llama Parsing API.)rf   rg   r)   Nz+The organization ID for the LlamaParse API.r*   z&The project ID for the LlamaParse API.r+      z8The interval in seconds to check if the parsing is done.check_intervalzcControls the backoff pattern when retrying failed requests: 'constant', 'linear', or 'exponential'.backoff_pattern   zNMaximum interval in seconds between polling attempts when checking job status.max_check_intervalz2A custom HTTPX client to use for sending requests.custom_clientz?Whether or not to ignore and skip errors raised during parsing.ignore_errorsi  zAThe maximum timeout in seconds to wait for the parsing to finish.max_timeout   r      z>The number of workers to use sending API requests for parsing.)rf   gtltrg   num_workerszThe result type for the parser.result_typez*Show progress when parsing multiple files.show_progressz1Whether to split by page using the page separatorsplit_by_pagez-Whether to print the progress of the parsing.verboseFzNIf set to true, LlamaParse will try to detect long table and adapt the output.adaptive_long_tablez:Annotate links found in the document to extract their URL.annotate_linkszIf set to true, the parser will automatically select the best mode to extract text from documents based on the rules provide. Will use the 'accurate' default mode by default and will upgrade page that match the rule to Premium mode.	auto_modezA JSON string containing the configuration for the auto mode. If set, the parser will use the provided configuration for the auto mode.auto_mode_configuration_jsonzdIf auto_mode is set to true, the parser will upgrade the page that contain an image to Premium mode."auto_mode_trigger_on_image_in_pagezcIf auto_mode is set to true, the parser will upgrade the page that contain a table to Premium mode."auto_mode_trigger_on_table_in_pagezdIf auto_mode is set to true, the parser will upgrade the page that contain the text to Premium mode.!auto_mode_trigger_on_text_in_pagezdIf auto_mode is set to true, the parser will upgrade the page that match the regexp to Premium mode.#auto_mode_trigger_on_regexp_in_pagezAzure Openai API Versionazure_openai_api_versionzAzure Openai Deployment Nameazure_openai_deployment_namezAzure Openai Endpointazure_openai_endpointzAzure Openai Keyazure_openai_keyzThe bottom margin of the bounding box to use to extract text from documents expressed as a float between 0 and 1 representing the percentage of the page height.bbox_bottomzThe left margin of the bounding box to use to extract text from documents expressed as a float between 0 and 1 representing the percentage of the page width.	bbox_leftzThe right margin of the bounding box to use to extract text from documents expressed as a float between 0 and 1 representing the percentage of the page width.
bbox_rightzThe top margin of the bounding box to use to extract text from documents expressed as a float between 0 and 1 representing the percentage of the page height.bbox_topzaIf set to true, the parser will output compact markdown table (without trailing spaces in cells).compact_markdown_tablezhParse documents continuously, leading to better results on documents where tables span across two pages.continuous_modezbDisable the OCR on the document. LlamaParse will only extract the copyable text from the document.disable_ocrz]If set to true, the parser will not extract images from the document. Make the parser faster.disable_image_extractionzIf set to true, the document will not be cached. This mean that you will be re-charged it you reprocess them as they will not be cached.do_not_cachezIf set to true, the parser will keep column in the text according to document layout. Reduce reconstruction accuracy, and LLM's/embedings performances in most case.do_not_unroll_columnszEIf set to true, the parser will extract/tag charts from the document.extract_chartszgIf set to true, the parser will extract the layout information of the document. Cost 1 credit per page.extract_layoutzNote: Non compatible with gpt-4o. If set to true, the parser will use a faster mode to extract text from documents. This mode will skip OCR of images, and table/heading reconstruction.	fast_modez2Whether to guess the sheet names of the xlsx file.guess_xlsx_sheet_nameszIf set to true, the parser will use high resolution OCR to extract text from images. This will increase the accuracy of the parsing job, but reduce the speed.high_res_ocrzmIf set to true, when parsing HTML the parser will consider all elements display not element as display block.html_make_all_elements_visiblezgIf set to true, when parsing HTML the parser will remove fixed elements. Useful to hide cookie banners.html_remove_fixed_elementszsIf set to true, when parsing HTML the parser will remove navigation elements. Useful to hide menus, header, footer.html_remove_navigation_elementszX(optional) If set with input_url will use the specified http proxy to download the file.
http_proxyznIf set to true, the parser will ignore document elements for layout detection and only rely on a vision model.-ignore_document_elements_for_layout_detectionz@The region of the input S3 bucket if input_s3_path is specified.input_s3_regionzIf set to true, the cache will be ignored and the document re-processes. All document are kept in cache for 48hours after the job was completed to avoid processing the same document twice.invalidate_cachezjThe extra time in seconds to wait for the parsing to finish per page. Get added to job_timeout_in_seconds.*job_timeout_extra_time_per_page_in_secondszThe maximum timeout in seconds to wait for the parsing to finish. Override default timeout of 30 minutes. Minimum is 120 seconds.job_timeout_in_secondsenz"The language of the text to parse.languagezeThe separator to use to split the header of the markdown table into multiple lines. Default is: <br/>)markdown_table_multiline_header_separatorzThe maximum number of pages to extract text from documents. If set to 0 or not set, all pages will be that should be extracted will be extracted (can work in combination with targetPages).	max_pageszIf set to true, the parser will merge tables across pages in the markdown output. This is useful for documents with tables that span across multiple pages.%merge_tables_across_pages_in_markdownz\If set to true, the parser will also output a PDF of the document. (except for spreadsheets)output_pdf_of_documentzAn S3 path prefix to store the output of the parsing job. If set, the parser will upload the output to S3. The bucket need to be accessible from the LlamaIndex organization.output_s3_path_prefixzHThe AWS region of the output S3 bucket defined in output_s3_path_prefix.output_s3_regionzFIf set to true, the parser will output tables as HTML in the markdown.output_tables_as_HTMLzIf set to true, the parser will use a dedicated approach to extract tables with outlined cells. This is useful for documents with spreadsheet-like tables where cells are outlined with borders. This could lead to false positives, so use with caution.outlined_table_extractionzThe error tolerance for the number of pages with error in a doc (percentage express as 0-1). If we fail to parse a greater percentage of pages than the tolerance value we fail the job.page_error_tolerancezA templated prefix to add to the beginning of each page. If it contain `{page_number}`, it will be replaced by the page number.page_prefixzA templated  page separator to use to split the text.  If it contain `{page_number}`,it will be replaced by the next page number. If not set will the default separator '\n---\n' will be used.page_separatorzA templated suffix to add to the beginning of each page. If it contain `{page_number}`, it will be replaced by the page number.page_suffixzBThe parsing mode to use, see ParsingMode enum for possible values 
parse_modez(Use our best parser mode if set to True.premium_modezThe preset to use for the parser. If set, the parser will use the preset configuration. See LlamaParse documentation for available presets. Preset override most other parameters.presetz1Preserve grid alignment across page in text mode.&preserve_layout_alignment_across_pageszIf set, the parser will try to preserve very small text lines. This can be useful for documents containing vector graphics with very small text lines that may not be recognized by OCR or a vision model (such as in CAD drawings).preserve_very_small_textzThe mode to use to replace the failed page, see FailedPageMode enum for possible value. If set, the parser will replace the failed page with the specified mode. If not set, the default mode (raw_text) will be used.replace_failed_page_modezYA prefix to add before error message in failed pages. If not set, no prefix will be used.-replace_failed_page_with_error_message_prefixzXA suffix to add after error message in failed pages. If not set, no suffix will be used.-replace_failed_page_with_error_message_suffixzlIf set to true, the parser will ignore diagonal text (when the text rotation in degrees modulo 90 is not 0).skip_diagonal_textzvIf set to true, the parser will extract sub-tables from the spreadsheet when possible (more than one table per sheet).spreadsheet_extract_sub_tableszfIf set to true, the parser will fail if it can't extract text from a document because of a buggy font.strict_mode_buggy_fontzTIf set to true, the parser will fail if it can't extract an image from the document.strict_mode_image_extractionzPIf set to true, the parser will fail if it can't OCR an image from the document.strict_mode_image_ocrzdIf set to true, the parser will fail if it can't reconstruct a table or a heading from the document.strict_mode_reconstructionzYIf set to true, the parser will output structured data based on the provided JSON Schema.structured_outputzA JSON Schema to use to structure the output of the parsing job. If set, the parser will output structured data based on the provided JSON Schema.structured_output_json_schemazThe named JSON Schema to use to structure the output of the parsing job. For convenience / testing, LlamaParse provides a few named JSON Schema that can be used directly. Use 'imFeelingLucky' to let llamaParse dream the schema."structured_output_json_schema_namezPThe system prompt. Replace llamaParse default system prompt, may impact accuracysystem_promptz*String to append to default system prompt.system_prompt_appendz8Whether to take screenshot of each page of the document.take_screenshotzThe target pages to extract text from documents. Describe as a comma separated list of page numbers. The first page of the document is page 0target_pagesz7The user prompt. Replace llamaParse default user promptuser_promptz#The API key for the multimodal API.vendor_multimodal_api_keyz-The model name for the vendor multimodal API.vendor_multimodal_model_namez;The document model name to be used with `parse_with_agent`.modelz<A URL that needs to be called at the end of the parsing job.webhook_urlzIf set, documents will automatically be partitioned into segments containing the specified number of pages at most. Parsing will be split into separate jobs for each partition segment. Can be used in combination with targetPages and maxPages.r'   z/Whether to hide page header in output markdown.hide_headersz0Whether to hide page footers in output markdown.hide_footersz:A suffix to add to the page header in the output markdown.page_header_suffixz:A prefix to add to the page header in the output markdown.page_header_prefixz:A suffix to add to the page footer in the output markdown.page_footer_suffixz:A prefix to add to the page footer in the output markdown.page_footer_prefixzoThe bounding box to use to extract text from documents describe as a string containing the bounding box marginsbounding_boxzThe complemental formatting instruction for the parser. Tell llamaParse how some thing should to be formatted, while retaining the markdown output.#complemental_formatting_instructionzfThe content guideline for the parser. Tell LlamaParse how the content should be changed / transformed.content_guideline_instructionzThe Formatting instruction for the parser. Override default llamaParse behavior. In most case you want to use complemental_formatting_instruction instead.formatting_instructionz2Whether to use gpt-4o extract text from documents.
gpt4o_modez;The API key for the GPT-4o API. Lowers the cost of parsing.gpt4o_api_keyzcAllow the parsing instruction to also format the output. Disable to have a cleaner markdown output.is_formatting_instructionz'The parsing instruction for the parser.parsing_instructionz)Whether to use the vendor multimodal API.use_vendor_multimodal_modelbefore)modedatar,   c                     [        X5      u  p#U(       aT  U Vs/ s H  nSU 3PM
     nnSR                  U5      n[        R                  " SSR                  U5      -   SU 3-   5        U$ s  snf )Nz
 - re   z%The following parameters are unused: z, z.
)r   r1   warningswarn)rK   r   extra_paramssuggestions
suggestionsuggestions_strs         r6   warn_extra_paramsLlamaParse.warn_extra_params   sz     %7s$A!BMN+JU:,/+KN ggk2OMM7))L)*()*  Os   A+)r   check_fieldsr5   c                 b    U(       d'  SSK nUR                  " SS5      nUc  [        S5      eU$ U$ )zValidate the API key.r   NLLAMA_CLOUD_API_KEYzThe API key is required.)osgetenv
ValueError)rK   r5   r   ri   s       r6   validate_api_keyLlamaParse.validate_api_key/  s6     ii 5t<G !;<<NrF   c                 `    [         R                  " SS5      nU=(       d    U=(       d    [        $ )zValidate the base URL.LLAMA_CLOUD_BASE_URLN)r   r   r   )rK   r5   urls      r6   validate_base_urlLlamaParse.validate_base_url=  s&     ii.5+a+++rF   )rf   init_aclientc                 N   U R                   (       d-  U R                  =(       d    [        R                  " 5       U l         U R                  U R                   l        SU R
                   3U R                   R                  S'   U R                  U R                   l        U R                   $ )NzBearer Authorization)	r   ro   httpxAsyncClientr)   ri   headersrq   timeout)rB   s    r6   aclientLlamaParse.aclientF  sq    }} ..E%2C2C2EDM "&3:4<<.1Io. $ 0 0}}rF   c                   #    U R                   b  U R                   7v   g[        R                  " U R                  S9 ISh  vN nU7v   SSS5      ISh  vN   g N N! , ISh  vN  (       d  f       g= f7f)z&Create a context for the HTTPX client.Nr   )ro   r   r   rq   )rB   clients     r6   client_contextLlamaParse.client_contextW  sR      )$$$((1A1ABBf CBBBBBsH   A A;AA;A!A;AA;A;!A8'A*(A84A;	file_pathc                     [        U[        5      (       d  g [        U5      n[        UR                  S;   UR
                  UR                  /5      $ ! [         a     gf = f)zCheck if the input is a valid URL.

This method checks for:
- Proper URL scheme (http/https)
- Valid URL structure
- Network location (domain)
F)httphttps)
isinstancerT   r   allschemenetloc	Exception)rB   r   results      r6   _is_input_urlLlamaParse._is_input_url`  sd     )S))
	i(FMM%66MMMM   		s   9A 
AAc                 P    [        U[        5      (       a  UR                  S5      $ g)zWCheck if the input is a valid URL.

This method checks for:
- Proper S3 scheme (s3://)
zs3://F)r  rT   
startswith)rB   r   s     r6   
_is_s3_urlLlamaParse._is_s3_urlv  s%     i%%''00rF   
file_input
extra_infofspartition_target_pagesc           	        #    S nS nU R                  U5      (       a  UOS nU R                  U5      (       a  UOS n[        U[        [        45      (       a=  U(       a  SU;  a  [        S5      eUS   n	[        R                  " U	5      S   n
SXU
40nOUb  S nOUb  S nO[        U[        [        [        [        45      (       a  [        U5      n[        R                  R                  U5      S   R                  5       nU[         ;  a  [#        S[          SU 35      e[        R                  " U5      S   n
U=(       d
    [%        5       nUR'                  US5      nS[        R                  R)                  U5      Xj40nO[        S	5      e0 nS
US'   U R*                  (       a  U R*                  US'   U R,                  (       a  U R,                  US'   U R.                  (       a  U R.                  US'   U R0                  b  U R0                  US'   U R2                  (       a  U R2                  US'   U R4                  (       a  U R4                  US'   U R6                  b  U R6                  US'   U R8                  b  U R8                  US'   U R:                  b  U R:                  US'   U R<                  b  U R<                  US'   U R>                  b  U R>                  US'   U R@                  b  U R@                  US'   U RB                  b  U RB                  US'   U RD                  b  U RD                  US'   U RF                  b  U RF                  US'   U RH                  b  U RH                  US'   U RJ                  (       a  U RJ                  US'   U RL                  (       a  [O        S5        U RL                  US'   U RP                  (       a  [O        S5        U RP                  US '   U RR                  (       a  U RR                  US!'   U RT                  (       a  U RT                  US"'   U RV                  (       a  U RV                  US#'   U RX                  (       a  U RX                  US$'   U RZ                  (       a  U RZ                  US%'   U R\                  (       a  U R\                  US&'   U R^                  (       a  U R^                  US''   U R`                  (       a  U R`                  US('   U Rb                  (       a  [O        S)5        U Rb                  US*'   U Rd                  (       a  U Rd                  US+'   U Rf                  (       a  U Rf                  US,'   U Rh                  (       a  U Rh                  US-'   U Rj                  (       a  U Rj                  US.'   U Rl                  (       a  U Rl                  US/'   U Rn                  b  U Rn                  US0'   U Rp                  (       a  U Rp                  US1'   Ub  S n[        U5      US2'   Ub  S n[        U5      US3'   U Rr                  b  U Rr                  US4'   U Rt                  (       a  U Rt                  US5'   U Rv                  (       a  [O        S)5        U Rv                  US6'   U Rx                  b  U Rx                  US7'   U Rz                  b  U Rz                  US8'   U R|                  (       a  U R|                  US9'   U R~                  b  U R~                  US:'   U R                  (       a  U R                  US;'   U R                  b  U R                  US<'   U R                  b  U R                  US='   U R                  (       a  U R                  US>'   U R                  (       a  U R                  US?'   U R                  b  U R                  US@'   U R                  b  U R                  USA'   U R                  (       a  U R                  USB'   U R                  (       a  U R                  USC'   U R                  (       a  U R                  USD'   U R                  b  U R                  USE'   U R                  b  U R                  USF'   U R                  b  U R                  USG'   U R                  b  U R                  USH'   U R                  b  U R                  USI'   U R                  b  U R                  USJ'   U R                  (       a  [O        SK5        U R                  USL'   U R                  (       a  U R                  USM'   U R                  (       a  U R                  USN'   U R                  (       a  U R                  USO'   U R                  (       a  U R                  USP'   U R                  b  U R                  USQ'   U R                  b  U R                  R                  USR'   U R                  b  U R                  USS'   U R                  b  U R                  UST'   U R                  (       a  U R                  USU'   U R                  (       a  U R                  USV'   U R                  (       a  U R                  USW'   U R                  (       a  U R                  USX'   U R                  (       a  U R                  USY'   U R                  (       a  U R                  USZ'   U R                  (       a  U R                  US['   U R                  b  U R                  US\'   U R                  b  U R                  US]'   U R                  b  U R                  US^'   U R                  b  U R                  US_'   U R                  (       a  U R                  US`'   Ub  XMSa'   OU R                  b  U R                  USa'   U R                  b  U R                  USb'   U R                  (       a  U R                  USc'   U R                  b  U R                  USd'   U R                  b  U R                  USe'   U R                  b  U R                  USf'   U R                  b  U R                  USg'   U R                  b  U R                  USh'   U R                  b  U R                  USi'   U R                  (       a  U R                  USj'   U R                  b  U R                  USk'    [        [        U R                  U R                  5      n[        U R                  SlXR                  X]Sm9I S h  vN nUR                  5         UR                  5       Sn   Ub  UR                  5         $ $  N;! [        R                   a*  nSoUR                  R                   3n[#        U5      UeS nAff = f! Ub  UR                  5         f f = f7f)pN	file_name;file_name must be provided in extra_info when passing bytesr   filerj   z8Currently, only the following file types are supported: z
Current file type: rbzJfile_input must be either a file path string, file bytes, or buffer objectTfrom_python_packager{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   zWARNING: complemental_formatting_instruction is deprecated and may be remove in a future release. Use system_prompt, system_prompt_append or user_prompt instead.r   zWARNING: content_guideline_instruction is deprecated and may be remove in a future release. Use system_prompt, system_prompt_append or user_prompt instead.r   r   r   r   r   r   r   r   r   zWARNING: formatting_instruction is deprecated and may be remove in a future release. Use system_prompt, system_prompt_append or user_prompt instead.r   r   r   r   r   r   r   r   	input_urlinput_s3_pathr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zkWARNING: parsing_instruction is deprecated. Use system_prompt, system_prompt_append or user_prompt instead.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   r   r   POST)r   filesr   rI   zFailed to parse the file: )r  r  r  bytesr   r   	mimetypes
guess_typerT   r   r	   r   r   pathsplitextlowerr   r  r   openbasenamer{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   printr   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   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   valuer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   JOB_UPLOAD_ROUTEr*   r+   r&   r   rq   raise_for_statusjsoncloser   HTTPStatusErrorresponsetext)rB   r  r  r  r  r  file_handler  r  r  	mime_typer   file_extr   r   resperrmsgs                     r6   _create_jobLlamaParse._create_job  s     "&"4"4Z"@"@Jd	&*ooj&A&A
tj5."9::J!> Q  #;/I!,,Y7:IiY?@E"E&E
S$x$HIIJIww''	215;;=H33NOcNd e**25  ",,Y7:I '~'B''*d3Kbgg..y9;RSE\   "&*"###*.*B*BD&'%)%8%8D!">> $D,,8373T3TD/022 77 4 22 77 4 11= 66 3 33? 88 5 ((4/3/L/LD+,,,8373T3TD/0%%1,0,F,FD()  ,'+'<'<D#$'"&"2"2D>>% $D??&!%D==$#}}D&&-1-H-HD)*33 t
 88 5 -- n 594V4VD01&*&:&:D"#"&"2"2D((/3/L/LD+,#'#4#4D %%,0,F,FD()%)%8%8D!"%)%8%8D!">> $D&& g .2-H-HD)*&&-1-H-HD)*..595X5XD12#'#4#4D **151P1PD-.// 44 1 ??&!%D== BB ?  E #ID$E$'$6D!+&*&:&:D"#  '+'<'<D#$)) g 150N0ND,-::F ?? < &&2-1-H-HD)*==#}}D>>% $D&&-1-H-HD)*%%1,0,F,FD()  ,'+'<'<D#$%%,0,F,FD()))040N0ND,-$$0+/+D+DD'('"&"2"2D55 :: 7 #'#4#4D #'#4#4D "".)-)@)@D%&"".)-)@)@D%&"".)-)@)@D%&"".)-)@)@D%& *%)%8%8D!"'"&"2"2D##} +/*B*BD&'??!%D#'#4#4D 66 ;; 8 ((/3/L/LD+,;;"![[DN((4/3/L/L/R/RD+,==I BB ? ==I BB ? "")-)@)@D%&..595X5XD12&&-1-H-HD)*,,373T3TD/0%%,0,F,FD()**151P1PD-.!!(,(>(>D$%--9484V4VD0122> 77 4 )$($6$6D!$$0+/+D+DD'(&*&:&:D"#!-#9 *#'#4#4D '"&"2"2D++262R2RD./))5040N0ND,-,,8373T3TD/0::! JJDM'"&"2"2D99E >> ;
 (#'#4#4D ??!%D)$($6$6D!
	$,d.B.BDOOTC)$,,M]M]ejvvD!!#99;t$
 &!!# ' w $$ 	*.s||/@/@.ABCC.c)	* &!!# 'sI   ru6At t&t u6t u0%uuu u33u6current_intervalc                 F   U R                   [        R                  :X  a  U$ U R                   [        R                  :X  a"  [	        US-   [        U R                  5      5      $ U R                   [        R                  :X  a"  [	        US-  [        U R                  5      5      $ U$ )zCalculate the next backoff interval based on the backoff pattern.

Args:
    current_interval: The current interval in seconds

Returns:
    The next interval in seconds
rj      )rl   rY   r_   r`   minfloatrn   ra   )rB   r5  s     r6   _calculate_backoffLlamaParse._calculate_backoff  s     >#:#::##!!^%:%::'!+U43J3J-KLL!!^%?%??'!+U43J3J-KLLrF   r;   c           
        #    [         R                   " 5       nSnSn[        U R                  5      nU R                  n  [        R
                  " U5      I S h  vN   US-  nUR                  [        R                  US95      I S h  vN n	U	R                  5         U	R                  5       n
U
S   nUS:X  a:  UR                  [        R                  XS95      I S h  vN nUR                  5       $ US:X  ab  [         R                   " 5       nX-
  U R                  :  a  [        S	U 35      eU(       a  US
-  S:X  a  [        SSSS9  U R                  U5      nO[         R#                  U
5      eGM3   GN N N! [$        R&                  [$        R(                  [$        R*                  [$        R,                  [$        R.                  [$        R0                  [$        R2                  [$        R4                  4 at  nUS-  n[         R                   " 5       nX-
  U R                  :  a  [        S	U 35      UeU(       a  US
-  S:X  a  [        SU S3SS9  U R                  U5      n S nANS nAff = f7f)Nr   Trj   )r;   r<   SUCCESS)r;   rw   PENDINGz Timeout while parsing the file: 
   .re   )endflushzHTTP error: z...)rB  )timer9  rk   r   asynciosleeprJ   JOB_STATUS_ROUTEformatr'  r(  JOB_RESULT_URLrq   r  r$  r:  r9   rL   r   ConnectError	ReadError
WriteErrorConnectTimeoutReadTimeoutWriteTimeoutr*  RemoteProtocolError)rB   r;   rw   rz   starttrieserror_countr5  r   r  rG   r<   parsed_resultrA  r1  s                  r6   _get_job_resultLlamaParse._get_job_result  s3     		"'(;(;"<
 +Mmm$4555
%zz*:*A*A*A*PQQ'')$kkm$X.Y&*0**&--V-U+ %M )--//y())+C{T%5%55'*J6((STT52:?cr6'+'>'>?O'P$,88EE- 5Q% ""  $$!!""%%))	 M q iik;!1!11#:6(C urzQ&se3/" $(#:#:;K#L +Ms   <I-E8 E1.E8 E4AE8 E6E8 0I-1A'E8 I-E8 .I-1E8 4E8 6E8 8A>I*6A*I% I-%I**I-c                    #    U R                   c  U R                  UUUUS9I S h  vN /nU$ U R                  UUUUUS9I S h  vN nU$  N$ N7f)N)r  r  rw   r  rw   rv   )r'   _parse_one_unpartitioned_parse_one_partitioned)rB   r   r  r  rw   rv   job_resultss          r6   
_parse_oneLlamaParse._parse_oneH  s      '33) +	 4  K   !% ; ;'' !< ! K s!   #AA
AAAAcreate_kwargsc                   #    U R                   " U4X#S.UD6I Sh  vN nU R                  (       a  [        SU-  5        U R                  Xd=(       d    U R                  R
                  U R                  S9I Sh  vN nXg4$  Ne N	7f)z-Create one parse job and wait for the result.r  r  Nz(Started parsing the file under job_id %srz   )r3  rz   r$  rT  rw   r%  )rB   r   r  r  rw   r]  r;   r  s           r6   rX  #LlamaParse._parse_one_unpartitionedc  s      ''
",
7D
 
 <<<vEF++94#3#3#9#94<< , 
 
 ~


s"   BBAB9B:BBc                   #    U R                   c   eU=(       d    U R                  nUS:  a  [        S5      eU R                  bq  [        [	        U R                  5      U R                   U R
                  S9 Vs/ s H  nU R                  UUUUUS9PM     nn[        UUSU R                  S9I Sh  vN $ Sn/ n	U R
                  b  XR
                  :  Ga?  U R
                  b,  XR                   -   U R
                  :  a  U R
                  U-
  n
OU R                   n
U
(       d   U	$  U R                  UUU[        R                  R                  U S	X-   S-
   3S9I Sh  vN u  pU=(       d    U R                  R                  nU[        R                  R                  :X  a  UnO#U R                  XU R                  S
9I Sh  vN n U	R#                  X45        [%        US   5      U
:  a   U	$ X-  nU R
                  c  GM-  XR
                  :  a  GM?  U	$ s  snf  GNl N N^! [         a$  nU	(       a  UR                   S:X  a  U	s SnA$ e SnAff = f7f)zCPartition a file and run separate parse jobs per partition segment.Nrj   zInvalid number of workers)r   )r  r  rw   r  Getting job resultsworkersdescrx   r   -r`  NO_DATA_FOUND_IN_FILEpages)r'   rv   r   r   r#   r   rX  r   rx   r    JSONr%  rw   rT  rz   r9   r=   appendlen)rB   r   r  r  rw   rv   r   jobstotalresultssizer;   json_result
job_resultes                  r6   rY  !LlamaParse._parse_one_partitionedv  sl     ##///!5T%5%5?899( %4'(9(9:(("nn%%L --) ++7 . %   "#*"00	   46nn$(>*000DNNB~~-++6 5 -1,I,I) * 5 5.3WAelQ6F5G+H -J - '# *CT-=-=-C-C*//"7"77!,J'+';';T\\ (< ( "J NNF/0;w'(4/ MEG nn$(>H w,'" & q||/FF"N	s   A7I9HI1H2A4I'8H$ H  AH$ %I&H$ H"H$ 9III H$ "H$ $
I.IIIIIIc                   ^ #     T R                  XX5S9I Sh  vN  VVs/ s H  u  pgUPM	     nnnT R                  =(       d    [        n	[        U	R	                  U 4S jU 5       5      U=(       d    0 S9/n
T R
                  (       a  T R                  U
5      $ U
$  Ns  snnf ! [         aH  n[        U[        5      (       a  UOSn[        SU S3U5        T R                  (       a  / s SnA$ UeSnAff = f7f)Load data from the input path.)r  rv   Nc              3   T   >#    U  H  oTR                   R                     v   M     g 7fN)rw   r%  ).0r  rB   s     r6   	<genexpr>)LlamaParse._aload_data.<locals>.<genexpr>  s#      (EL6t//556Ws   %(r,  metadata<bytes/buffer>Error while parsing the file '':)r[  r   _DEFAULT_SEPARATORr   r1   ry   _get_sub_docsr  r  rT   r$  rp   )rB   r   r  r  rz   rv   _rr  ro  	separatordocsrs  	file_reprs   `            r6   _aload_dataLlamaParse._aload_data  s    	 ,0??b ,; , & &&MA &   ++A/AI" (EL(  (-2	D !!))$//#&*  	%/	3%?%?	EUI29+R@!D!!		sg   C8B# BB# BA*B# C8B# C8B# B# #
C5-;C0(C5)C8.C00C55C8c                   #    [        U[        [        [        [        [
        45      (       a"  U R                  XX0R                  S9I Sh  vN $ [        U[        5      (       a  U Vs/ s H8  nU R                  UUUU R                  =(       a    U R                  (       + SS9PM:     nn [        UU R                  SU R                  S9I Sh  vN nU VVs/ s H  ow  H  oPM     M     snn$ [        S5      e Ns  snf  N3s  snnf ! [         a)  n	[        [        U	5      ;   a  [        [        5      eU	eSn	A	ff = f7f)zLoad data from the input path.

File(s) which were partitioned before parsing will be loaded as a single
re-assembled Document.
)r  r  rz   Nrj   )r  r  rz   rv   Parsing filesrd  :The input file_path must be a string or a list of strings.)r  rT   r	   r   r  r   r  rz   listrx   r   rv   RuntimeErrorr$   r%   r   )
rB   r   r  r  frm  ro  sublistitemrs  s
             r6   
aload_dataLlamaParse.aload_data  sI     i#}dE>!RSS))R *    	4(( #	 #A   ) LLC1C1C-C ! !  #  	 ( ,,("&"4"4	!  -4HGGHH L =	 I #s1v-&'788G	sl   AD?
C:D?(?C<'D?*#D	 D	D	 D+D	 .D?<D?D	 D	 	
D<$D77D<<D?c                      [        U R                  XUS95      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)rv  r  N)r   r  r  r$   rT   r%   rB   r   r  r  rs  s        r6   	load_dataLlamaParse.load_data  sL    	tyLMM 	3q6)"#344		    
A$A		Ar  c                 2  #    U R                  UUU[        R                  R                  US9I S h  vN nU VVs/ s HI  u  px[	        UUUU R
                  U R                  U R                  U R                  =(       d    [        S9PMK     snn$  N]s  snnf 7f)NrW  r;   r  rr  ri   r)   r   r   )
r[  r    rj  r%  r   ri   r)   r   r   r  )	rB   r   r  r  r  rv   rZ  r;   rr  s	            r6   _aparse_oneLlamaParse._aparse_one&  s      !OO"--# , 
 
" '2
 '2" #%||#22H6H '2
 	


s!   /BB	BABBBr   c                   #    [        U[        [        [        [        [
        45      (       ar  [        U[        [
        45      (       a  U(       a  SU;  a  [        S5      eUS   nO[        U5      nU R                  XX#S9I Sh  vN n[        U5      S:X  a  US   $ U$ [        U[        5      (       a  / nU Hf  n[        U[        [
        45      (       a.  U(       a  SU;  a  [        S5      eUR                  US   5        ML  UR                  [        U5      5        Mh     / n [        [        U5       V	Vs/ s H  u  pU R                  UXi   UUSS9PM     snn	U R                  SU R                  S	9I Sh  vN  H  nUR                  U5        M     U$ [        S
5      e GNs  snn	f  N2! [          a)  n
["        [        U
5      ;   a  [!        [$        5      eU
eSn
A
ff = f7f)a]  
Parse the file and return a JobResult object instead of Document objects.

This method is similar to aload_data but returns JobResult objects that provide
direct access to the various output formats (text, markdown, json, etc.)

Args:
    file_path: Path to the file to parse. Can be a string, path, bytes, file-like object, or a list of these.
    extra_info: Additional metadata to include in the result.
    fs: Optional filesystem to use for reading files.

Returns:
    JobResult object or list of JobResult objects if either multiple files were provided or file(s) were partitioned before parsing.
r  r  r_  Nrj   r   )r  r  rv   rc  rd  r  )r  rT   r	   r   r  r   r   r  rl  r  rk  r   	enumeraterv   rx   extendr  r$   r%   )rB   r   r  r  r  r  
file_namesr  rZ  irs  s              r6   aparseLlamaParse.aparseB  s    * i#}dE>!RSS)e^%<==![
%B$U  '{3		N	++ ,  F !$Fq 06!9<f<	4((Ja%!899%J)F(Y  %%j&=>%%c!f-  K$, %.i$8	 %9DA ((&M'1!() )  %9	 !,,."&"4"4%  F  &&v.  #" L W(	$   #s1v-&'788G	sU   BG$F#BG$%F. 8!F&
 F. 9F,:F. G$&F. .
G!8$GG!!G$c                      [        U R                  XUS95      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)a)  
Parse the file and return a JobResult object instead of Document objects.

This method is similar to load_data but returns JobResult objects that provide
direct access to the various output formats (text, markdown, json, etc.)

Args:
    file_path: Path to the file to parse. Can be a string, path, bytes, file-like object, or a list of these.
    extra_info: Additional metadata to include in the result.
    fs: Optional filesystem to use for reading files.

Returns:
    JobResult object or list of JobResult objects if multiple files were provided
r  N)r   r  r  r$   rT   r%   r  s        r6   parseLlamaParse.parse  sL    (	t{{9R{HII 	3q6)"#344		r  c                   #     U R                  UU[        R                  R                  US9I Sh  vN n/ nU HC  u  pgXgS'   [	        U[
        [        45      (       d  [        U5      US'   UR                  U5        ME     U$  NQ! [         aH  n[	        U[        5      (       a  UOSn	[        SU	 S3U5        U R                  (       a  / s SnA$ UeSnAff = f7f)rv  )r  rw   rv   Nr;   r   r~  r  r  )r[  r    rj  r%  r  r  r   rT   rk  r  r$  rp   )
rB   r   r  rv   rZ  ro  r;   rr  rs  r  s
             r6   
_aget_jsonLlamaParse._aget_json  s     	 $%&OO11'	 !0 ! K G&1"'-8$!)e^-DEE.1)nJ{+z*	 '2
 N  	%/	3%?%?	EUI29+R@!D!!		sK   C-B BAB CB 
C;C
CCCCCc                   #    [        U[        [        [        [        [
        45      (       a  U R                  XS9I Sh  vN $ [        U[        5      (       ad  U Vs/ s H  o0R                  X2S9PM     nn [        UU R                  SU R                  S9I Sh  vN nU VVs/ s H  of  H  owPM     M     snn$ [        S5      e Ns  snf  N3s  snnf ! [         a)  n[        [        U5      ;   a  [        [        5      eUeSnAff = f7f)rv  )r  Nr  rd  z\The input file_path must be a string, Path, bytes, BufferedIOBase, or a list of these types.)r  rT   r	   r   r  r   r  r  r   rv   rx   r  r$   r%   r   )	rB   r   r  r  rm  ro  r  r  rs  s	            r6   	aget_jsonLlamaParse.aget_json  s      i#}dE>!RSSJJJ	4((GPQy!OOAO=yDQ ( ,,("&"4"4	!  -4HGGHH n ' KQ I #s1v-&'788G	sj   =DC DC
5D8#C C	C %C9C <D
DC C 
D
!$DD

Dc                      [        U R                  X5      5      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)zParse the input path.N)r   r  r  r$   rT   r%   )rB   r   r  rs  s       r6   get_json_resultLlamaParse.get_json_result  sH    	t~~iDEE 	3q6)"#344		    
A$A

Ac                 $    U R                  X5      $ )rv  )r  )rB   r   r  s      r6   get_jsonLlamaParse.get_json  s     ##I::rF   rq  download_path	asset_keyc                   #    [         R                  R                  U5      (       d  [         R                  " U5        U R                  n / nU GH]  nUS   nUS    GHJ  nU R
                  (       a'  [        SUR                  5        SUS    SX    35        X    GH  n	U	S   n
[         R                  R                  X' SU
 35      nUR                  S	5      (       d  UR                  S
5      (       d  US	-  nXS'   XyS'   UR                  SS5      U	S'   US   U	S'   [        US5       nU R                   SU SU
 3n[        USXR                  S9I Sh  vN nUR                  5         UR!                  UR"                  5        SSS5        UR%                  U	5        GM     GMM     GM`     U$  NY! , (       d  f       N2= f! [&         a/  n[        SU S3U5        U R(                  (       a  / s SnA$ UeSnAff = f7f)z:Download assets (images or charts) from the parsed result.r;   ri  z> z
 for page pagez: namerg  z.pngz.jpgr  r   Noriginal_file_pathpage_numberwb/api/parsing/job/z/result/image/GETr   zError while downloading z from the parsed result:)r   r  existsmakedirsr   rz   r$  
capitalizer1   endswithrJ   r"  r)   r&   rq   r'  writecontentrk  r  rp   )rB   rq  r  r  r   assetsr  r;   r  asset
asset_name
asset_pathr  	asset_urlr0  rs  s                   r6   aget_assetsLlamaParse.aget_assets  s    
 ww~~m,,KK&)	F%)"7OD|| !5!5!7 8
4<.PRSWSbRcd "&%*6]
 &(WW\\)XQzl+C&

  *226::#-#6#6v#>#> *f 4
(2f*0h6<jjd6S23/3F|m,!*d3q+/==/9J6(R`ak`l(mI)9 &yBRBR* $D !113GGDLL1 4 e,3 "1 , &B M$ 43  	,YK7OPRST!!		sg   AH
C!G +-F4	F2/F4	)G 1H2F4	4
G>G 
G>"G91G>2H7G99G>>Hc                    #     U R                  XS5      I Sh  vN $  N! [         a+  n[        SU5        U R                  (       a  / s SnA$ UeSnAff = f7f)'Download images from the parsed result.imagesNzError while downloading images:r  r  r$  rp   rB   rq  r  rs  s       r6   aget_imagesLlamaParse.aget_images1  P     	))+hOOOO 	3Q7!!		B   A    A  
AAA	AAAAc                    #     U R                  XS5      I Sh  vN $  N! [         a+  n[        SU5        U R                  (       a  / s SnA$ UeSnAff = f7f)'Download charts from the parsed result.chartsNzError while downloading charts:r  r  s       r6   aget_chartsLlamaParse.aget_charts>  r  r  c                      [        U R                  X5      5      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)r  N)r   r  r  r$   rT   r%   r  s       r6   
get_imagesLlamaParse.get_imagesK  J    	t//KLL 	3q6)"#344		r  c                      [        U R                  X5      5      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)r  N)r   r  r  r$   rT   r%   r  s       r6   
get_chartsLlamaParse.get_chartsU  r  r  json_resultsc                     [         R                  R                  U5      (       d  [         R                  " U5        [	        X5      $ rx  )r   r  r  r  r(   )rB   r  r  s      r6   
get_tablesLlamaParse.get_tables_  s,    ww~~m,,KK&/LLrF   c                 `   #    [         R                  " U R                  X5      I S h  vN $  N7frx  )rD  	to_threadr  )rB   rq  r  s      r6   aget_tablesLlamaParse.aget_tablesd  s$      &&tSSSSs   %.,.c           	        #    [         R                  R                  U5      (       d  [         R                  " U5        U R                  n / nU H  nUS   nU R
                  (       a  [        S5        [         R                  R                  X& S35      n0 nXxS'   XhS'   UR                  SS5      US'   [        US5       n	U R                   S	U S
3n
[        USXR                  S9I Sh  vN nUR                  5         U	R                  UR                  5        SSS5        UR!                  U5        M     U$  NN! , (       d  f       N'= f! ["         a+  n[        SU5        U R$                  (       a  / s SnA$ UeSnAff = f7f)%Download xlsx from the parsed result.r;   z> XLSXz.xlsxr  r   Nr  r  r  z/result/raw/xlsxr  r   zError while downloading xlsx:)r   r  r  r  r   rz   r$  r1   rJ   r"  r)   r&   rq   r'  r  r  rk  r  rp   )rB   rq  r  r   	xlsx_listr  r;   	xlsx_pathxlsxr  xlsx_urlresrs  s                r6   	aget_xlsxLlamaParse.aget_xlsxi  sY    
 ww~~m,,KK& 	I%)<<(OGGLL(%8HI	(V!'X-3ZZT-J)*)T*a==/):6(BRS  !1x9I9I! C ((*GGCKK( +   &- &. 	 +*  	115!!		sg   AF
A5E ?+D;*D9+/D;E 8F9D;;
E		E 
FE<4F5F:E<<FFc                      [        U R                  X5      5      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)r  N)r   r  r  r$   rT   r%   r  s       r6   get_xlsxLlamaParse.get_xlsx  sH    	t~~kIJJ 	3q6)"#344		r  r  c                     / nU R                   =(       d    [        nU HU  nUR                  R                  U5      nU H1  n[	        U[        UR                  5      S9nUR                  U5        M3     MW     U$ )z$Split docs into pages, by separator.r|  )r   r  r,  splitr   r   r}  rk  )rB   r  sub_docsr  doc
doc_chunks	doc_chunksub_docs           r6   r  LlamaParse._get_sub_docs  sl    ''=+=	C	2J'	""%cll3 ( (  rF   c                 4  #    [        U[        5      (       a  U R                  U[        R                  R
                  U R                  S9I Sh  vN n[        USUU R                  U R                  U R                  U R                  =(       d    [        S9$ [        U[        5      (       a  / nU Vs/ s H6  nU R                  U[        R                  R
                  U R                  S9PM8     nn[        UU R                  SU R                   S9I Sh  vN n[#        U5       VVs/ s HK  u  pb[        X   SUU R                  U R                  U R                  U R                  =(       d    [        S9PMM     snn$ [%        S5      e GN:s  snf  N{s  snnf 7f)2  
Return JobResult object for previously parsed job(s).

If the job is still pending, the result will not be returned until it is completed.

Args:
    job_id: Job ID or list of multiple Job IDs to be retrieved.

Returns:
    JobResult object or list of JobResult objects if multiple job IDs were provided.
r`  Nre   r  rc  rd  z7The input job_id must be a string or a list of strings.)r  rT   rT  r    rj  r%  rz   r   ri   r)   r   r   r  r  r   rv   rx   r  r   )rB   r;   r  ro  id_rm  r  s          r6   aget_resultLlamaParse.aget_result  s     fc""//
--t|| 0  F !||#22H6H  %%G "!C $$S*//*?*?$V!   %((*"00	 G  "+7!3 "4IA !9 % LL!]]<<#'#6#6#L:L "4  VWWKsD   AFFA#F2=F/%FFF'AF9FFFc                      [        U R                  U5      5      $ ! [         a)  n[        [	        U5      ;   a  [        [
        5      eUeSnAff = f)r  N)r   r  r  r$   rT   r%   )rB   r;   rs  s      r6   
get_resultLlamaParse.get_result  sJ    	t//788 	3q6)"#344		r  )r   )NNN)F)NNNN)NNFNrN   rx  )rO   rP   rQ   rR   rS   r   ri   rT   __annotations__r   r)   r*   r   r+   rk   intrY   r`   rl   rn   ro   r   r   rp   boolrq   rv   r    TXTrw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r9  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   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   r   r   r   r   r   r'   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r
   r   r   r   r   r   r   propertyr   r   r   r   	FileInputr  r  dictr   r3  r:  rT  r   r   r[  rX  rY  r   r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rV   r^   rF   r6   rc   rc   l   s   # 9GS 
  <Hc  &+A&OXc]  !&<!J   NNC 
 ',%%y'O^  $d 
 27"V2M8E--.   UM4  WK  T	K  $,MK   "NM4   GM4  "QGT 
 +0d+$  &+P&NHTN  !& !Ix~  38 ^3 (3-  :?z:&  :?y:&  8=z8%x}  :?z:'#  /4"</hsm  38"@3 (3-  ,1"9,8C=  ',"4'hsm  $) w$K%  "' t"Ix  #( u#J  !& t!Hhuo  .3w.HTN  ',~'OXd^  #(x#K$  05s0htn  $) _$L(4.  -2 {-8D>  &+[&NHTN  &+}&NHTN  !& O!Ix~ 
 .3H.HTN  $) u$L(4.  6; D6"HTN  27}2  7< J7#Xd^  !&n!J  EJ EE18D>  &+V&OXc]  (- S(htn  CH AC.  /4 X/HUO  $"FHhsm  @E{@-x}   % S Ix}  =B r=)8D>  .3r.HTN  ,1 D,8C=  ',^'hsm  -2\-8D>  16 P1x~  -2 O-(5/  "' V"K#  %* X%NHSM  "' V"K#  5:X5J{C/01  $)>$L(4.  " IFHSM  >CG>*HTN  05 {0htn  :? m:h~6  DIoD18C=  DInD18C=  */ C*  6; M6"HTN 
 .3|.HTN 
 49j4 (4. 
 -2f-8D> 
 27z2 
 ).o)x~  49 i4!8C=  9> z9&  $)f$M8C=  +0@+(3-  ',N'OXd^  #( d#L(3-  "'M"K#  0590x}  38C3 (3-  !QE8C=  "'R"K#  &+ I&OXc]  $)E$L(4.  $)F$L(4.  ).P)  ).P)  ).P)  ).P)  #( F#L(3-  :? j:'#  49|4!8C=  -2 q-HSM  "'H"J  $)Q$M8C=  16y1x~  */ I*#  38?3$ 
 (#T#s(^ S#X   $ YXDA
 
 
  B
 ZhTB,# ,# ,  C,
 0;4e/THeE%%t+,T**    nU5F5F5L&M  y T ,I $  &*+/04z$z$ TNz$ '(	z$
 !)z$ 
z$x 5  U  $ >C8M8M(+8M6:8M	c3h8Mz &*+/%)%) TN '(	
 c] c] 
eCc3h'(	)< &*+/%) TN '(	
 c]  
sDcN"	#, &*+/%)%)JJ TNJ '(	J
 c]J c]J 
eCc3h'(	)J^ &*+/%)%% TN% '(	%
 % c]% 
h%T &*+/	,i)34, TN, '(	,
 
h,b &*+/	i)34 TN '(	
 
h& &*+/%)

 
 TN	

 '(
 c]
 
i
> &*+/	Ki)34K TNK '(	K
 
tK +-	.K` &*+/	i)34 TN '(	
 
tK +-	.> &*%)	 TN c]	
 
dB &*i)34 TN 
d	B &*i)34 TN 
d	" &*;i)34; TN; 
d	;2:2692FI2	d2h:69	d:69	dd4j  d d4j  d MtDz M# M$s) M
T:T69T	cT
(:(69(	d(TDJ s tDz $x. T(^ 4XCcN+4X	y$y/)	*4XlCcN+	y$y/)	* rF   rc   )IrD  r  r   rC  r   
contextlibr   copyr   enumr   ior   pathlibr   r   r	   typingr
   r   r   r   r   r   r   urllib.parser   r   fsspecr   llama_index.core.async_utilsr   r    llama_index.core.bridge.pydanticr   r   r   r   llama_index.core.constantsr   llama_index.core.readers.baser   "llama_index.core.readers.file.baser   llama_index.core.schemar   llama_cloud_services.utilsr    llama_cloud_services.parse.typesr    llama_cloud_services.parse.utilsr   r    r!   r"   r#   r$   r%   r&   r'   r(   rT   r  r	  r  rH  rF  r&  r7   r  r9   rY   rc   r^   rF   r6   <module>r     s      	   *    1 1 J J J !  % >  8 < = , 9 6   #un,-	  B. ( $,SM?G}W W< S$  J# JrF   