o
    5tii                     @   s   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ eeZG d	d
 d
eZdddZdddZ	ddededee fddZdS )z List and inspect metrics.    )OptionalN)DownloadConfig   )EVALUATION_MODULE_TYPESHF_LIST_ENDPOINT)evaluation_module_factory)
get_loggerc                   @   s   e Zd ZdS )SplitsNotFoundErrorN)__name__
__module____qualname__ r   r   D/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/inspect.pyr	      s    r	   TFc                 C   s^   | du rg }t D ]} |t| ||d q|S | t vr&td|  dt  dt| ||d}|S )a  List all evaluation modules available on the Hugging Face Hub.

    Args:
        module_type (`str`, *optional*, defaults to `None`):
            Type of evaluation modules to list. Has to be one of `'metric'`, `'comparison'`, or `'measurement'`. If `None`, all types are listed.
        include_community (`bool`, *optional*, defaults to `True`):
            Include community modules in the list.
        with_details (`bool`, *optional*, defaults to `False`):
            Return the full details on the metrics instead of only the ID.

    Returns:
        `List[Union[str, dict]]`

    Example:

    ```py
    >>> from evaluate import list_evaluation_modules
    >>> list_evaluation_modules(module_type="metric")
    ```
    N)include_communitywith_detailszInvalid module type 'z'. Has to be one of .)r   extend_list_evaluation_modules_type
ValueError)module_typer   r   evaluations_listr   r   r   list_evaluation_modules#   s   r   c                    s   t tj d}|  | }|s fdd|D }|D ]$}|d dd d  kr>|d dd |d< d	|d
< qd|d
< q|rN fdd|D S dd |D S )N)typec                    s,   g | ]}|d   dd d  kr|qS )id/r   	evaluate-)split.0elementr   r   r   
<listcomp>Q   s   , z1_list_evaluation_modules_type.<locals>.<listcomp>r   r   r   r   r   F	communityTc              	      s*   g | ]}|d   |d | dddqS )r   r"   likesr   )namer   r"   r#   )getr   r    r   r   r!   \   s    
c                 S   s   g | ]}|d  qS )r   r   r   r   r   r   r!   f   s    )requestsr%   r   formatraise_for_statusjsonr   )r   r   r   rdr   r   r    r   r   J   s   



r   path
local_pathdownload_configc              
   K   s>   t | f||d|}td|  d| d|j d| d	 dS )a  
    Allow inspection/modification of a evaluation script by copying it on local drive at local_path.

    Args:
        path (``str``): path to the evaluation script. Can be either:

            - a local path to script or the directory containing the script (if the script has the same name as the directory),
                e.g. ``'./metrics/accuracy'`` or ``'./metrics/accuracy/accuracy.py'``
            - a dataset identifier on the Hugging Face Hub (list all available datasets and ids with ``evaluate.list_evaluation_modules()``)
                e.g. ``'accuracy'``, ``'bleu'`` or ``'word_length'``
        local_path (``str``): path to the local folder to copy the datset script to.
        download_config (Optional ``datasets.DownloadConfig``: specific download configuration parameters.
        **download_kwargs: optional attributes for DownloadConfig() which will override the attributes in download_config if supplied.
    )r.   force_local_pathz"The processing scripts for metric z can be inspected at z. The main class is in zH. You can modify this processing scripts and use it with `evaluate.load(z)`.N)r   printmodule_path)r,   r-   r.   download_kwargsevaluation_moduler   r   r   inspect_evaluation_modulei   s   r4   )NTF)TF)N)__doc__typingr   r&   datasetsr   configr   r   loadingr   utils.loggingr   r
   loggerr   r	   r   r   strr4   r   r   r   r   <module>   s&   

' 