o
    /if                     @  s   d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 eeZdddZd ddZd!ddZe	jg de	jddge	jddge	jddge	jddge	jg de	jg diZefd"ddZdS )#    )annotationsN)DatasetSequence)ContextPrecision)EvaluationModeMetricdatasetr   
column_mapdict[str, str]returnc                 C  s   dd |  D }| |S )zL
    Remap the column names in case dataset uses different column names
    c                 S  s   i | ]\}}||qS  r   ).0kvr   r   I/var/www/html/corbot_env/lib/python3.10/site-packages/ragas/validation.py
<dictcomp>   s    z&remap_column_names.<locals>.<dictcomp>)itemsrename_columns)r   r	   inverse_column_mapr   r   r   remap_column_names   s   
r   dsc                 C  sp   d| j v r6d| j vr6d}t| j | tr6| j | jjdkr6td dd | d D }| jd|| jd d} | S )	Nground_truthsground_truthstringzpassing column names as 'ground_truths' is deprecated and will be removed in the next version, please use 'ground_truth' instead. Note that `ground_truth` should be of type string and not Sequence[string] like `ground_truths`c                 S  s   g | ]}|d  qS )r   r   )r   gtr   r   r   
<listcomp>    s    z3handle_deprecated_ground_truths.<locals>.<listcomp>a)new_fingerprint)	features
isinstancer   featuredtypeloggerwarning
add_column_fingerprint)r   column_namesr   r   r   r   handle_deprecated_ground_truths   s"   r'   c                 C  s   dD ]}|| j v r| j | jdkrtd| dqdD ]'}|| j v rCt| j | tr4| j | jjdksCtd| dt| j |  qd S )N)questionanswerr   r   zDataset feature "z" should be of type string)contextsz*" should be of type Sequence[string], got )r   r!   
ValueErrorr   r   r    type)r   r&   r   r   r   validate_column_dtypes*   s&   


r-   )r(   r)   r*   r(   r)   r*   r   )r(   r   r)   )r(   r*   r   metricslist[Metric]evalmode_to_columnsdictc                 C  sr   |D ]4}t ||j }t | j }||s6d}t|tr$d|vr$d}td|j dt	||  d| qdS )z
    validates the dataset and returns the evaluation type

    possible evaluation types
    1. (q,a,c)
    2. (q,a)
    3. (q,c)
    4. (g,a)
     r   zLooks like you're trying to use 'context_precision' without ground_truth. Please use consider using  `context_utilization' instead.zThe metric [z>] that that is used requires the following additional columns z to be present in the dataset. N)
setevaluation_moder   keysissubsetr   r   r+   namelist)r   r.   r0   mrequired_columnsavailable_columns	extra_msgr   r   r   validate_evaluation_modesI   s$   


r=   )r   r   r	   r
   r   r   )r   r   r   r   )r   r   )r   r   r.   r/   r0   r1   )
__future__r   loggingdatasetsr   r    ragas.metrics._context_precisionr   ragas.metrics.baser   r   	getLogger__name__r"   r   r'   r-   qacqaqcgcgaqgaqcgEVALMODE_TO_COLUMNSr=   r   r   r   r   <module>   s&    


	







