o
    diA                     @   s   d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZ 			dde	eef d	ed
edee dee	eef  defddZ					dde	eef deded
edee	eef  dee	eef  dee dee fddZdS )zPUtility functions related to both local files and files on the Hugging Face Hub.    N)Path)ListOptionalUnion)HfApi)http_user_agent model_name_or_pathfilename	subfolderrevisiontokenreturnc                 C   sJ   t j| rt jt j| ||S tt |djt j||| ||dS )zl
    Checks that the file called `filename` exists in the `model_name_or_path` directory or model repo.
    
user_agentr   )r
   repo_idr   r   )ospathisdirisfilejoinr   r   file_exists)r	   r
   r   r   r    r   f/lsinfo/ai/hellotax_ai/llm_service/venv_embed/lib/python3.10/site-packages/optimum/utils/file_utils.pyvalidate_file_exists   s   r   **/*patternglob_patternuse_auth_tokenc           
         s   |durt dt |durtd|}t| trt| n| }t|   t	j
|r>t||} fdd|D }|S tt |dj|||d}	 fdd|	D }|S )	a  
    Scans either a model repo or a local directory to find filenames matching the pattern.

    Args:
        model_name_or_path (`Union[str, Path]`):
            The name of the model repo on the Hugging Face Hub or the path to a local directory.
        pattern (`str`):
            The pattern to use to look for files.
        glob_pattern (`str`, defaults to `"**/*"`):
            The pattern to use to list all the files that need to be checked.
        subfolder (`str`, defaults to `""`):
            In case the model files are located inside a subfolder of the model directory / repo on the Hugging
            Face Hub, you can specify the subfolder name here.
        use_auth_token (`Optional[Union[bool,str]]`, defaults to `None`):
            Deprecated. Please use the `token` argument instead.
        token (`Optional[Union[bool,str]]`, defaults to `None`):
            The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
            when running `huggingface-cli login` (stored in `huggingface_hub.constants.HF_TOKEN_PATH`).
        token (`Optional[Union[bool, str]]`, *optional*):
            The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
            when running `transformers-cli login` (stored in `~/.huggingface`).
        revision (`Optional[str]`, defaults to `None`):
            Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id.

    Returns:
        `List[Path]`
    NznThe `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.zLYou cannot use both `use_auth_token` and `token` arguments at the same time.c                    s    g | ]}t  t|r|qS r   )researchstr.0pr   r   r   
<listcomp>c        z/find_files_matching_pattern.<locals>.<listcomp>r   )r   r   c                    s    g | ]}t  |rt|qS r   )r   matchr   r"   r%   r   r   r&   h   r'   )warningswarnFutureWarning
ValueError
isinstancer   r!   r   compiler   r   r   globr   r   list_repo_files)
r	   r   r   r   r   r   r   
model_pathfiles
repo_filesr   r%   r   find_files_matching_pattern1   s&   %r4   )r   NN)r   r   NNN)__doc__r   r   r)   pathlibr   typingr   r   r   huggingface_hubr   transformers.utilsr   r!   boolr   r4   r   r   r   r   <module>   s\   


