
    Ji              	       h   d dl Z d dlZd dlmZ d dlmZ d dlZd dlm	Z	m
Z
 d dlZd dlZd dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlZd	Zd
Zdee   deeef   deee   ee   f   fdZ de	de!fdZ"ddejF                  de!de!fdZ$eded   fd       Z% G d d      Z&eeeee&e
f   Z'y)    N)contextmanager)	Generator)
StatusEnumFile)	BaseModel)AnyDictListTupleTypeUnionOptional)BufferedIOBaseTextIOWrapper)Pathz*cannot be called from a running event loopzrThe event loop is already running. Add `import nest_asyncio; nest_asyncio.apply()` to your code to fix this issue.	model_clsdatareturnc           
      R   t        | j                  j                               }|j                         D cg c]	  }||vs| }}g }|rV|D ]Q  }t        j                  ||dd      }|r|j                  d| d|d    d| d       =|j                  d| d	       S ||fS c c}w )
N   g?)ncutoff'z*' is not a valid parameter. Did you mean 'r   z' instead of 'z'?zQ' is not a valid parameter. Please check the documentation or update the package.)setmodel_fieldskeysdifflibget_close_matchesappend)r   r   model_attributesparamextra_paramssuggestionssimilar_paramss          l/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/llama_cloud_services/utils.pycheck_extra_paramsr&      s     9116689'+yy{TeeCS6SETLTK! 	E$66'1SN ""wHXYIZH[[ijoipprs ""wop	 $$% Us   	B$ B$statusc                     | t         j                  t         j                  t         j                  t         j                  hv S )a  
    Check if a status is terminal, i.e. the job is done and no more updates are expected.
    Note: this must be updated if the status enum is updated.

    Args:
        status: The status to check

    Returns:
        True if the status is terminal, False otherwise
    )r   SUCCESSERROR	CANCELLEDPARTIAL_SUCCESS)r'   s    r%   is_terminal_statusr-   1   s:     ""	      clientquietc                   K   d}| j                  d| d       d{   }|j                         j                  di       j                  dd      }|st        d      t        j                  j                  |      }t        j                  j                  t        j                  j	                  |            }||k  r:|s7d	| d
d| d| dg}t        t        j                  j                  |             y|st        | d       y7 w)a&  Check if an SDK update is available.

    Args:
        client: HTTPX client to use.
        quiet: If False, update availability will also be printed to stdout.

    Returns: True if an update is available.

    Raises:
        ValueError: Failed to get a valid release version from PyPI.
    zllama-cloud-serviceszhttps://pypi.org/pypi/z/jsonNinfoversion z&Failed to fetch package info from PyPIu   ⚠️ z is out of datezCurrent version: u    | Latest: zATo upgrade: pip install -U --force-reinstall llama-cloud-servicesTz is up to dateF)getjson
ValueError	packagingr3   parse	importlibmetadataprintoslinesepjoin)r/   r0   package_namerr3   latestcurrentmsgs           r%   check_for_updatesrE   D   s      *Ljj1,uEFFAffhll62&**9b9GABB$$W-F%%i&8&8&@&@&NOG~_=#G9OF8DSC
 "**//#&'n-.# 	Gs   DD
C-D)NNNc               #   z   K   	 d y# t         $ r&} t        t        |       v rt        t               d} ~ ww xY ww)zPContext manager to add helpful information for errors due to nested event loops.N)RuntimeErrornest_asyncio_errstrnest_asyncio_msg)es    r%   augment_async_errorsrL   e   s8      s1v%/00s   ;	 ;	8!38;c            
       `    e Zd ZdZddddddeeeeee	df   de
e   de
e   de
e   fdZd
d	Zy)
SourceTexta}  
    A wrapper class for providing text or file input with optional filename specification.

    This class allows you to provide input in multiple ways:
    - Direct text content via text_content parameter
    - File paths as strings or Path objects
    - Raw bytes
    - File-like objects (BufferedIOBase, TextIOWrapper)
    - Already-uploaded file ID via file_id parameter

    Args:
        file: The file input (bytes, file-like object, str path, or Path).
              Mutually exclusive with text_content and file_id.
        text_content: Raw text content to process. Mutually exclusive with file and file_id.
        file_id: ID of an already-uploaded file. Mutually exclusive with file and text_content.
        filename: Optional filename. Required for bytes/file-like objects without names.
                  If not provided, will be auto-generated for text_content or inferred from paths.

    Examples:
        # Direct text input
        source = SourceText(text_content="Hello world")

        # File path
        source = SourceText(file="document.pdf")

        # Bytes with filename
        source = SourceText(file=b"...", filename="document.pdf")

        # File-like object (will read from current position)
        with open("document.pdf", "rb") as f:
            source = SourceText(file=f)

        # Already-uploaded file
        source = SourceText(file_id="file_abc123")
    N)filetext_contentfile_idfilenamerO   rP   rQ   rR   c                \    || _         || _        || _        || _        | j	                          y )N)rO   rR   rP   rQ   	_validate)selfrO   rP   rQ   rR   s        r%   __init__zSourceText.__init__   s+     	 (r.   c                    t        | j                  du| j                  du| j                  dug      }|dk(  rt	        d      |dkD  rt	        d      | j                  y| j                  -| j
                  s t        j                  d      }d| d| _        yt        | j                  t        t        t        f      r| j
                  sXt        | j                  d	      rBt        j                  j                  t!        | j                  j"                              | _        y| j
                  "t        | j                  d	      st	        d
      yyt        | j                  t         t$        f      rE| j
                  s8t        j                  j                  t!        | j                              | _        yyt	        dt'        | j                               )z(Ensure filename is provided when needed.Nr   z7One of file, text_content, or file_id must be provided.r   z;Only one of file, text_content, or file_id can be provided.   text_input_z.txtnamezQfilename must be provided when file is bytes or a file-like object without a namezUnsupported file type: )sumrO   rP   rQ   r7   rR   secrets	token_hex
isinstancebytesr   r   hasattrr=   pathbasenamerI   rZ   r   type)rU   provided
random_hexs      r%   rT   zSourceText._validate   s    		%!!-D(
 q=VWW\M 
 <<#(==$..q1
"-j\ >dii%!GH==WTYY%? " 0 0TYY^^1D E&wtyy&/I g  0J& 		C;/== " 0 0TYY @ ! 6tDII6GHIIr.   )r   N)__name__
__module____qualname____doc__r   r_   r   r   rI   r   r   rV   rT    r.   r%   rN   rN   p   si    "N NR&*!%"& E>=#tTIJ sm	
 # 3-'Jr.   rN   )T)(r=   importlib.metadatar:   
contextlibr   typingr   r   llama_cloud.typesr   r   httpxpackaging.versionr8   pydanticr   r   r	   r
   r   r   r   r   ior   r   pathlibr   r\   rH   rJ   rI   r&   boolr-   AsyncClientrE   rL   rN   	FileInputrj   r.   r%   <module>rw      s    	  %   .    @ @ @ ,   @ V %I%&*38n%
49d3i %4z d &E$5$5 d d B i(89  ZJ ZJ| #t^Z=>	r.   