Ë
    ´ŒjL7  ã                   óú   — d 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
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ defd„Z G d„ dee«      Z G d„ de«      Z G d„ dee«      Z G d„ dee«      Zy)z:String distance evaluators based on the RapidFuzz library.é    )ÚEnum)ÚAnyÚCallableÚOptional)Ú	Callbacks)ÚAsyncCallbackManagerForChainRunÚCallbackManagerForChainRun)Úpre_init)ÚField)Úoverride)ÚChain)ÚPairwiseStringEvaluatorÚStringEvaluator)ÚRUN_KEYÚreturnc                  ób   — 	 ddl } | j                  S # t        $ r}d}t        |«      |‚d}~ww xY w)z¬
    Load the RapidFuzz library.

    Raises:
        ImportError: If the rapidfuzz library is not installed.

    Returns:
        Any: The rapidfuzz.distance module.
    r   NzyPlease install the rapidfuzz library to use the FuzzyMatchStringEvaluator.Please install it with `pip install rapidfuzz`.)Ú	rapidfuzzÚImportErrorÚdistance)r   ÚeÚmsgs      ús/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain/evaluation/string_distance/base.pyÚ_load_rapidfuzzr      sC   € ð&Ûð ×ÑÐøô ò &ð>ð 	ô ˜#Ó AÐ%ûð&ús   ‚ ’	.›)©.c                   ó(   — e Zd ZdZdZdZdZdZdZdZ	y)	ÚStringDistancea7  Distance metric to use.

    Attributes:
        DAMERAU_LEVENSHTEIN: The Damerau-Levenshtein distance.
        LEVENSHTEIN: The Levenshtein distance.
        JARO: The Jaro distance.
        JARO_WINKLER: The Jaro-Winkler distance.
        HAMMING: The Hamming distance.
        INDEL: The Indel distance.
    Údamerau_levenshteinÚlevenshteinÚjaroÚjaro_winklerÚhammingÚindelN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚDAMERAU_LEVENSHTEINÚLEVENSHTEINÚJAROÚJARO_WINKLERÚHAMMINGÚINDEL© ó    r   r   r   )   s(   „ ñ	ð 0ÐØ€KØ€DØ!€LØ€GØ�Er-   r   c                   ó  — e Zd ZU dZ eej                  ¬«      Zeed<    ed¬«      Z	e
ed<   	 edeeef   deeef   fd„«       Zedee   fd	„«       Zd
eeef   deeef   fd„Zeddœdede
defd„«       Zedefd„«       Zdededefd„Zy)Ú_RapidFuzzChainMixinz<Shared methods for the rapidfuzz string distance evaluators.)Údefaultr   TÚnormalize_scoreÚvaluesr   c                 ó   — t        «        |S )zÍ
        Validate that the rapidfuzz library is installed.

        Args:
            values (Dict[str, Any]): The input values.

        Returns:
            Dict[str, Any]: The validated values.
        )r   )Úclsr2   s     r   Úvalidate_dependenciesz*_RapidFuzzChainMixin.validate_dependenciesE   s   € ô 	ÔØˆr-   c                 ó   — dgS )z`
        Get the output keys.

        Returns:
            List[str]: The output keys.
        Úscorer,   ©Úselfs    r   Úoutput_keysz _RapidFuzzChainMixin.output_keysS   s   € ð ˆyÐr-   Úresultc                 ó`   — d|d   i}t         |v r|t            j                  «       |t         <   |S )zÊ
        Prepare the output dictionary.

        Args:
            result (Dict[str, Any]): The evaluation results.

        Returns:
            Dict[str, Any]: The prepared output dictionary.
        r7   )r   Údict)r9   r;   s     r   Ú_prepare_outputz$_RapidFuzzChainMixin._prepare_output]   s5   € ð ˜6 '™?Ð+ˆÜ�fÑØ$¤W™o×2Ñ2Ó4ˆF”7‰OØˆr-   F©r1   c                óÐ  — ddl m} t        j                  |j                  t        j
                  |j                  t        j                  |j                  t        j                  |j                  t        j                  |j                  t        j                  |j                  i}| |vr d| › dt        t        «      › �}t!        |«      ‚||    }|r|j"                  S |j                  S )a  
        Get the distance metric function based on the distance type.

        Args:
            distance (str): The distance type.

        Returns:
            Callable: The distance metric function.

        Raises:
            ValueError: If the distance metric is invalid.
        r   )r   zInvalid distance metric: z
Must be one of: )r   r   r   r&   ÚDamerauLevenshteinr'   ÚLevenshteinr(   ÚJaror)   ÚJaroWinklerr*   ÚHammingr+   ÚIndelÚlistÚ
ValueErrorÚnormalized_distance)r   r1   Úrf_distanceÚ
module_mapr   Úmodules         r   Ú_get_metricz _RapidFuzzChainMixin._get_metricl   sÍ   € õ 	6ô ×.Ñ.°×0NÑ0NÜ×&Ñ&¨×(?Ñ(?Ü×Ñ ×!1Ñ!1Ü×'Ñ'¨×)@Ñ)@Ü×"Ñ" K×$7Ñ$7Ü× Ñ  +×"3Ñ"3ð&
ˆ
ð ˜:Ñ%à+¨H¨:Ø$¤T¬.Ó%9Ð$:ð<ð ô ˜S“/Ð!Ø˜HÑ%ˆÙØ×-Ñ-Ð-Ø�‰Ðr-   c                 óX   — t         j                  | j                  | j                  ¬«      S )zy
        Get the distance metric function.

        Returns:
            Callable: The distance metric function.
        r?   )r/   rM   r   r1   r8   s    r   Úmetricz_RapidFuzzChainMixin.metric�   s,   € ô $×/Ñ/Ø�M‰MØ ×0Ñ0ð 0ó 
ð 	
r-   ÚaÚbc                 ó&   — | j                  ||«      S )zä
        Compute the distance between two strings.

        Args:
            a (str): The first string.
            b (str): The second string.

        Returns:
            float: The distance between the two strings.
        )rO   )r9   rP   rQ   s      r   Úcompute_metricz#_RapidFuzzChainMixin.compute_metricœ   s   € ð �{‰{˜1˜aÓ Ð r-   N)r"   r#   r$   r%   r   r   r)   r   Ú__annotations__r1   Úboolr
   r=   Ústrr   r5   ÚpropertyrG   r:   r>   Ústaticmethodr   rM   rO   ÚfloatrS   r,   r-   r   r/   r/   =   s  … ÙFá$¨^×-HÑ-HÔI€HˆnÓIÙ!¨$Ô/€O�TÓ/ðJð ð¨4°°S°©>ð ¸dÀ3ÈÀ8¹nò ó ðð ð˜T #™Yò ó ðð d¨3°¨8¡nð ¸¸cÀ3¸h¹ó ð Ø>Cò  ˜cð  °tð  Èò  ó ð ðD ð

˜ò 

ó ð

ð! ð !¨ð !°ô !r-   r/   c                   ó®  — e Zd ZdZedefd„«       Zedefd„«       Zedee	   fd„«       Z
ede	fd„«       Z	 ddee	ef   d	ee   dee	ef   fd
„Z	 ddee	ef   d	ee   dee	ef   fd„Zedddddddœde	dee	   dee	   dedeee	      deee	ef      dededefd„«       Zedddddddœde	dee	   dee	   dedeee	      deee	ef      dededefd„«       Zy)ÚStringDistanceEvalChainak  Compute string distances between the prediction and the reference.

    Examples
    ----------

    >>> from langchain.evaluation import StringDistanceEvalChain
    >>> evaluator = StringDistanceEvalChain()
    >>> evaluator.evaluate_strings(
            prediction="Mindy is the CTO",
            reference="Mindy is the CEO",
        )

    Using the `load_evaluator` function:

    >>> from langchain.evaluation import load_evaluator
    >>> evaluator = load_evaluator("string_distance")
    >>> evaluator.evaluate_strings(
            prediction="The answer is three",
            reference="three",
        )
    r   c                  ó   — y)z8
        This evaluator does not require input.
        Fr,   r8   s    r   Úrequires_inputz&StringDistanceEvalChain.requires_inputÁ   s   € ð
 r-   c                  ó   — y)z>
        This evaluator does not require a reference.
        Tr,   r8   s    r   Úrequires_referencez*StringDistanceEvalChain.requires_referenceÈ   s   € ð
 r-   c                 ó
   — ddgS )ú^
        Get the input keys.

        Returns:
            List[str]: The input keys.
        Ú	referenceÚ
predictionr,   r8   s    r   Ú
input_keysz"StringDistanceEvalChain.input_keysÏ   s   € ð ˜\Ð*Ð*r-   c                 ó4   — | j                   j                  › d�S )úb
        Get the evaluation name.

        Returns:
            str: The evaluation name.
        Ú	_distance©r   Úvaluer8   s    r   Úevaluation_namez'StringDistanceEvalChain.evaluation_nameÙ   s   € ð —-‘-×%Ñ%Ð& iÐ0Ð0r-   NÚinputsÚrun_managerc                 ó6   — d| j                  |d   |d   «      iS )a^  
        Compute the string distance between the prediction and the reference.

        Args:
            inputs (Dict[str, Any]): The input values.
            run_manager (Optional[CallbackManagerForChainRun]):
                The callback manager.

        Returns:
            Dict[str, Any]: The evaluation results containing the score.
        r7   rb   rc   ©rS   ©r9   rk   rl   s      r   Ú_callzStringDistanceEvalChain._callã   s&   € ð  ˜×,Ñ,¨V°KÑ-@À&ÈÑBVÓWÐXÐXr-   c              ƒ   ó>   K  — d| j                  |d   |d   «      iS ­w)a}  
        Asynchronously compute the string distance between the prediction
            and the reference.

        Args:
            inputs (Dict[str, Any]): The input values.
            run_manager (Optional[AsyncCallbackManagerForChainRun]:
                The callback manager.

        Returns:
            Dict[str, Any]: The evaluation results containing the score.
        r7   rb   rc   rn   ro   s      r   Ú_acallzStringDistanceEvalChain._acallõ   s*   è ø€ ð" ˜×,Ñ,¨V°KÑ-@À&ÈÑBVÓWÐXÐXùó   ‚F)rb   ÚinputÚ	callbacksÚtagsÚmetadataÚinclude_run_inforc   rb   rt   ru   rv   rw   rx   Úkwargsc                óD   —  | ||dœ||||¬«      }	| j                  |	«      S )aè  
        Evaluate the string distance between the prediction and the reference.

        Args:
            prediction (str): The prediction string.
            reference (Optional[str], optional): The reference string.
            input (Optional[str], optional): The input string.
            callbacks (Callbacks, optional): The callbacks to use.
            kwargs: Additional keyword arguments.

        Returns:
            dict: The evaluation results containing the score.
        ©rc   rb   ©rk   ru   rv   rw   rx   ©r>   ©
r9   rc   rb   rt   ru   rv   rw   rx   ry   r;   s
             r   Ú_evaluate_stringsz)StringDistanceEvalChain._evaluate_strings  s5   € ñ4 Ø",¸9ÑEØØØØ-ô
ˆð ×#Ñ# FÓ+Ð+r-   c             ‹   ór   K  — | j                  ||dœ||||¬«      ƒ d{  –—† }	| j                  |	«      S 7 Œ­w)a  
        Asynchronously evaluate the string distance between the
            prediction and the reference.

        Args:
            prediction (str): The prediction string.
            reference (Optional[str], optional): The reference string.
            input (Optional[str], optional): The input string.
            callbacks (Callbacks, optional): The callbacks to use.
            kwargs: Additional keyword arguments.

        Returns:
            dict: The evaluation results containing the score.
        r{   r|   N©Úacallr>   r~   s
             r   Ú_aevaluate_stringsz*StringDistanceEvalChain._aevaluate_strings,  sL   è ø€ ð6 —z‘zØ",¸9ÑEØØØØ-ð "ó 
÷ 
ˆð ×#Ñ# FÓ+Ð+ð
úó   ‚7Ÿ5 7©N)r"   r#   r$   r%   rW   rU   r]   r_   rG   rV   rd   rj   r=   r   r   r	   rp   r   rr   r   r   r   rƒ   r,   r-   r   r[   r[   ª   s;  „ ñð, ð ò ó ðð ð Dò ó ðð ð+˜D ™Iò +ó ð+ð ð1 ò 1ó ð1ð =AñYà�S˜#�X‘ðYð Ð8Ñ9ðYð 
ˆc�3ˆh‰ó	Yð* BFñYà�S˜#�X‘ðYð Ð=Ñ>ðYð 
ˆc�3ˆh‰ó	Yð& ð
 $(Ø#Ø#Ø$(Ø-1Ø!&ò!,ð ð!,ð ˜C‘=ð	!,ð
 ˜‰}ð!,ð ð!,ð �t˜C‘yÑ!ð!,ð ˜4  S ™>Ñ*ð!,ð ð!,ð ð!,ð 
ò!,ó ð!,ðF ð
 $(Ø#Ø#Ø$(Ø-1Ø!&ò!,ð ð!,ð ˜C‘=ð	!,ð
 ˜‰}ð!,ð ð!,ð �t˜C‘yÑ!ð!,ð ˜4  S ™>Ñ*ð!,ð ð!,ð ð!,ð 
ò!,ó ñ!,r-   r[   c                   óF  — e Zd ZdZedee   fd„«       Zedefd„«       Z	 dde	ee
f   dee   de	ee
f   fd„Z	 dde	ee
f   dee   de	ee
f   fd	„Zdddd
dœdedededeee      dee	ee
f      dede
de	fd„Zdddd
dœdedededeee      dee	ee
f      dede
de	fd„Zy)ÚPairwiseStringDistanceEvalChainz6Compute string edit distances between two predictions.r   c                 ó
   — ddgS )ra   rc   Úprediction_br,   r8   s    r   rd   z*PairwiseStringDistanceEvalChain.input_keysT  s   € ð ˜nÐ-Ð-r-   c                 ó6   — d| j                   j                  › d�S )rf   Ú	pairwise_rg   rh   r8   s    r   rj   z/PairwiseStringDistanceEvalChain.evaluation_name^  s   € ð ˜4Ÿ=™=×.Ñ.Ð/¨yÐ9Ð9r-   Nrk   rl   c                 ó6   — d| j                  |d   |d   «      iS )aN  
        Compute the string distance between two predictions.

        Args:
            inputs (Dict[str, Any]): The input values.
            run_manager (CallbackManagerForChainRun , optional):
                The callback manager.

        Returns:
            Dict[str, Any]: The evaluation results containing the score.
        r7   rc   r‰   rn   ro   s      r   rp   z%PairwiseStringDistanceEvalChain._callh  s*   € ð" �T×(Ñ(¨°Ñ)=¸vÀnÑ?UÓVð
ð 	
r-   c              ƒ   ó>   K  — d| j                  |d   |d   «      iS ­w)ab  
        Asynchronously compute the string distance between two predictions.

        Args:
            inputs (Dict[str, Any]): The input values.
            run_manager (AsyncCallbackManagerForChainRun , optional):
                The callback manager.

        Returns:
            Dict[str, Any]: The evaluation results containing the score.
        r7   rc   r‰   rn   ro   s      r   rr   z&PairwiseStringDistanceEvalChain._acall|  s.   è ø€ ð" �T×(Ñ(¨°Ñ)=¸vÀnÑ?UÓVð
ð 	
ùrs   F)ru   rv   rw   rx   rc   r‰   ru   rv   rw   rx   ry   c                óD   —  | ||dœ||||¬«      }| j                  |«      S )a$  
        Evaluate the string distance between two predictions.

        Args:
            prediction (str): The first prediction string.
            prediction_b (str): The second prediction string.
            callbacks (Callbacks, optional): The callbacks to use.
            tags (List[str], optional): Tags to apply to traces.
            metadata (Dict[str, Any], optional): Metadata to apply to traces.
            kwargs: Additional keyword arguments.

        Returns:
            dict: The evaluation results containing the score.
        ©rc   r‰   r|   r}   ©	r9   rc   r‰   ru   rv   rw   rx   ry   r;   s	            r   Ú_evaluate_string_pairsz6PairwiseStringDistanceEvalChain._evaluate_string_pairs�  s5   € ñ2 Ø",¸lÑKØØØØ-ô
ˆð ×#Ñ# FÓ+Ð+r-   c             ‹   ór   K  — | j                  ||dœ||||¬«      ƒ d{  –—† }| j                  |«      S 7 Œ­w)a3  
        Asynchronously evaluate the string distance between two predictions.

        Args:
            prediction (str): The first prediction string.
            prediction_b (str): The second prediction string.
            callbacks (Callbacks, optional): The callbacks to use.
            tags (List[str], optional): Tags to apply to traces.
            metadata (Dict[str, Any], optional): Metadata to apply to traces.
            kwargs: Additional keyword arguments.

        Returns:
            dict: The evaluation results containing the score.
        r�   r|   Nr�   r�   s	            r   Ú_aevaluate_string_pairsz7PairwiseStringDistanceEvalChain._aevaluate_string_pairs²  sL   è ø€ ð2 —z‘zØ",¸lÑKØØØØ-ð "ó 
÷ 
ˆð ×#Ñ# FÓ+Ð+ð
úr„   r…   )r"   r#   r$   r%   rW   rG   rV   rd   rj   r=   r   r   r	   rp   r   rr   r   rU   r‘   r“   r,   r-   r   r‡   r‡   Q  s«  „ Ù@àð.˜D ™Iò .ó ð.ð ð: ò :ó ð:ð =Añ
à�S˜#�X‘ð
ð Ð8Ñ9ð
ð 
ˆc�3ˆh‰ó	
ð. BFñ
à�S˜#�X‘ð
ð Ð=Ñ>ð
ð 
ˆc�3ˆh‰ó	
ð2  $Ø$(Ø-1Ø!&ò ,ð ð ,ð ð	 ,ð
 ð ,ð �t˜C‘yÑ!ð ,ð ˜4  S ™>Ñ*ð ,ð ð ,ð ð ,ð 
ó ,ðN  $Ø$(Ø-1Ø!&ò ,ð ð ,ð ð	 ,ð
 ð ,ð �t˜C‘yÑ!ð ,ð ˜4  S ™>Ñ*ð ,ð ð ,ð ð ,ð 
ô ,r-   r‡   N)r%   Úenumr   Útypingr   r   r   Úlangchain_core.callbacksr   Ú langchain_core.callbacks.managerr   r	   Úlangchain_core.utilsr
   Úpydanticr   Útyping_extensionsr   Úlangchain.chains.baser   Úlangchain.evaluation.schemar   r   Úlangchain.schemar   r   rV   r   r/   r[   r‡   r,   r-   r   Ú<module>rž      sz   ðÙ @å ß *Ñ *å .÷õ *Ý Ý &å 'ß PÝ $ð˜ó ô*�S˜$ô ô(j!˜5ô j!ôZd,˜oÐ/Cô d,ôNA,Ð&=Ð?Sõ A,r-   