§
    ™ŠtjA5  ã                   ó  — d 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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dS )z:String distance evaluators based on the RapidFuzz library.é    )ÚCallable)ÚEnum)ÚAny)Ú	Callbacks)ÚAsyncCallbackManagerForChainRunÚCallbackManagerForChainRun)Úpre_init)ÚField)Úoverride)ÚChain)ÚPairwiseStringEvaluatorÚStringEvaluator)ÚRUN_KEYÚreturnc                  ód   — 	 ddl } n$# t          $ r}d}t          |¦  «        |‚d}~ww xY w| j        S )z¤Load the RapidFuzz library.

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

    Returns:
        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      úo/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/evaluation/string_distance/base.pyÚ_load_rapidfuzzr      s\   € ð&ØÐÐÐÐøÝð &ð &ð &ð>ð 	õ ˜#ÑÔ AÐ%øøøøð&øøøð ÔÐs   ‚ ‡
(‘#£(c                   ó*   — e Zd ZdZdZdZdZdZdZdZ	dS )	ÚStringDistanceaC  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   )   s9   € € € € € ð	ð 	ð 0ÐØ€KØ€DØ!€LØ€GØ€E€E€Er,   r   c                   óV  — 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dS )Ú_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: The input values.

        Returns:
            The validated values.
        )r   )Úclsr1   s     r   Úvalidate_dependenciesz*_RapidFuzzChainMixin.validate_dependenciesE   s   € õ 	ÑÔÐØˆr,   c                 ó   — dgS )zLGet the output keys.

        Returns:
            The output keys.
        Úscorer+   ©Úselfs    r   Úoutput_keysz _RapidFuzzChainMixin.output_keysR   s   € ð ˆyÐr,   Úresultc                 óz   — d|d         i}t           |v r'|t                                         ¦   «         |t           <   |S )z Prepare the output dictionary.

        Args:
            result: The evaluation results.

        Returns:
            The prepared output dictionary.
        r6   )r   Údict)r8   r:   s     r   Ú_prepare_outputz$_RapidFuzzChainMixin._prepare_output[   s;   € ð ˜6 'œ?Ð+ˆÝ�fÐÐØ$¥Wœo×2Ò2Ñ4Ô4ˆF•7‰OØˆr,   F©r0   c                óh  — 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 )aB  Get the distance metric function based on the distance type.

        Args:
            distance: The distance type.
            normalize_score: Whether to normalize the score.

        Returns:
            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   r0   Úrf_distanceÚ
module_mapr   Úmodules         r   Ú_get_metricz _RapidFuzzChainMixin._get_metrici   sÊ   € ð 	6Ð5Ð5Ð5Ð5Ð5õ Ô.°Ô0NÝÔ&¨Ô(?ÝÔ Ô!1ÝÔ'¨Ô)@ÝÔ" KÔ$7ÝÔ  +Ô"3ð&
ˆ
ð ˜:Ð%Ð%ð<¨Hð <ð <Ý%)­.Ñ%9Ô%9ð<ð <ð õ ˜S‘/”/Ð!Ø˜HÔ%ˆØð 	.ØÔ-Ð-ØŒÐr,   c                 óN   — t                                | j        | j        ¬¦  «        S )zfGet the distance metric function.

        Returns:
            The distance metric function.
        r>   )r.   rL   r   r0   r7   s    r   Úmetricz_RapidFuzzChainMixin.metricŒ   s,   € õ $×/Ò/ØŒMØ Ô0ð 0ñ 
ô 
ð 	
r,   ÚaÚbc                 ó.   — |                       ||¦  «        S )zÈCompute the distance between two strings.

        Args:
            a: The first string.
            b: The second string.

        Returns:
            The distance between the two strings.
        )rN   )r8   rO   rP   s      r   Úcompute_metricz#_RapidFuzzChainMixin.compute_metric˜   s   € ð �{Š{˜1˜aÑ Ô Ð r,   N)r!   r"   r#   r$   r
   r   r(   r   Ú__annotations__r0   Úboolr	   r<   Ústrr   r4   ÚpropertyrF   r9   r=   Ústaticmethodr   rL   rN   ÚfloatrR   r+   r,   r   r.   r.   =   s�  € € € € € € ØFÐFà$˜u¨^Ô-HÐIÑIÔI€HˆnÐIÐIÑIØ!˜E¨$Ð/Ñ/Ô/€O�TÐ/Ð/Ñ/ðJð ð
¨4°°S°¬>ð 
¸dÀ3ÈÀ8¼nð 
ð 
ð 
ñ „Xð
ð ð˜T #œYð ð ð ñ „Xðð d¨3°¨8¤nð ¸¸cÀ3¸h¼ð ð ð ð ð Ø>Cð  ð  ð  ˜cð  °tð  Èð  ð  ð  ñ „\ð ðD ð	
˜ð 	
ð 	
ð 	
ñ „Xð	
ð
! ð 
!¨ð 
!°ð 
!ð 
!ð 
!ð 
!ð 
!ð 
!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e	 ddee	ef         d	edz  dee	ef         fd
„¦   «         Ze	 ddee	ef         d	edz  dee	ef         fd„¦   «         Zedddddddœde	de	dz  de	dz  dedee	         dz  dee	ef         dz  dededefd„¦   «         Zedddddddœde	de	dz  de	dz  dedee	         dz  dee	ef         dz  dededefd„¦   «         ZdS )ÚStringDistanceEvalChaina{  Compute string distances between the prediction and the reference.

    Examples:
    ----------
    >>> from langchain_classic.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_classic.evaluation import load_evaluator
    >>> evaluator = load_evaluator("string_distance")
    >>> evaluator.evaluate_strings(
            prediction="The answer is three",
            reference="three",
        )
    r   c                 ó   — dS )z&This evaluator does not require input.Fr+   r7   s    r   Úrequires_inputz&StringDistanceEvalChain.requires_input»   s	   € ð ˆur,   c                 ó   — dS )z,This evaluator does not require a reference.Tr+   r7   s    r   Úrequires_referencez*StringDistanceEvalChain.requires_referenceÀ   s	   € ð ˆtr,   c                 ó
   — ddgS )úJGet the input keys.

        Returns:
            The input keys.
        Ú	referenceÚ
predictionr+   r7   s    r   Ú
input_keysz"StringDistanceEvalChain.input_keysÅ   s   € ð ˜\Ð*Ð*r,   c                 ó    — | j         j        › d�S )úTGet the evaluation name.

        Returns:
            The evaluation name.
        Ú	_distance©r   Úvaluer7   s    r   Úevaluation_namez'StringDistanceEvalChain.evaluation_nameÎ   s   € ð ”-Ô%Ð0Ð0Ð0Ð0r,   NÚinputsÚrun_managerc                 óJ   — d|                       |d         |d         ¦  «        iS ©zýCompute the string distance between the prediction and the reference.

        Args:
            inputs: The input values.
            run_manager: The callback manager.

        Returns:
            The evaluation results containing the score.
        r6   ra   rb   ©rR   ©r8   rj   rk   s      r   Ú_callzStringDistanceEvalChain._call×   s)   € ð ˜×,Ò,¨V°KÔ-@À&ÈÔBVÑWÔWÐXÐXr,   c              ƒ   óN   K  — d|                       |d         |d         ¦  «        iS rm   rn   ro   s      r   Ú_acallzStringDistanceEvalChain._acallè   s-   è è € ð ˜×,Ò,¨V°KÔ-@À&ÈÔBVÑWÔWÐXÐXr,   F)ra   ÚinputÚ	callbacksÚtagsÚmetadataÚinclude_run_inforb   ra   rs   rt   ru   rv   rw   Úkwargsc                óR   —  | ||dœ||||¬¦  «        }	|                       |	¦  «        S )a$  Evaluate the string distance between the prediction and the reference.

        Args:
            prediction: The prediction string.
            reference: The reference string.
            input: The input string.
            callbacks: The callbacks to use.
            tags: The tags to apply.
            metadata: The metadata to use.
            include_run_info: Whether to include run info in the output.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation results containing the score.
        ©rb   ra   ©rj   rt   ru   rv   rw   ©r=   ©
r8   rb   ra   rs   rt   ru   rv   rw   rx   r:   s
             r   Ú_evaluate_stringsz)StringDistanceEvalChain._evaluate_stringsù   sG   € ð8 �Ø",¸9ÐEÐEØØØØ-ð
ñ 
ô 
ˆð ×#Ò# FÑ+Ô+Ð+r,   c             ‹   óv   K  — |                       ||dœ||||¬¦  «        ƒ d{V —†}	|                      |	¦  «        S )a&  Evaluate the string distance between the prediction and the reference.

        Args:
            prediction: The prediction string.
            reference: The reference string.
            input: The input string.
            callbacks: The callbacks to use.
            tags: The tags to apply.
            metadata: The metadata to apply.
            include_run_info: Whether to include run info in the output.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation results containing the score.
        rz   r{   N©Úacallr=   r}   s
             r   Ú_aevaluate_stringsz*StringDistanceEvalChain._aevaluate_strings  sk   è è € ð8 —z’zØ",¸9ÐEÐEØØØØ-ð "ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð ×#Ò# FÑ+Ô+Ð+r,   ©N)r!   r"   r#   r$   rV   rT   r\   r^   rF   rU   rc   ri   r   r<   r   r   rp   r   rr   r   r~   r‚   r+   r,   r   rZ   rZ   ¥   sò  € € € € € ðð ð* ð ð ð ð ñ „Xðð ð Dð ð ð ñ „Xðð ð+˜D œIð +ð +ð +ñ „Xð+ð ð1 ð 1ð 1ð 1ñ „Xð1ð ð :>ðYð Yà�S˜#�X”ðYð 0°$Ñ6ðYð 
ˆc�3ˆhŒð	Yð Yð Yñ „XðYð  ð ?CðYð Yà�S˜#�X”ðYð 5°tÑ;ðYð 
ˆc�3ˆhŒð	Yð Yð Yñ „XðYð  ð
 !%Ø Ø#Ø!%Ø*.Ø!&ð#,ð #,ð #,ð ð#,ð ˜‘:ð	#,ð
 �T‰zð#,ð ð#,ð �3Œi˜$Ñð#,ð �s˜C�x”. 4Ñ'ð#,ð ð#,ð ð#,ð 
ð#,ð #,ð #,ñ „Xð#,ðJ ð
 !%Ø Ø#Ø!%Ø*.Ø!&ð",ð ",ð ",ð ð",ð ˜‘:ð	",ð
 �T‰zð",ð ð",ð �3Œi˜$Ñð",ð �s˜C�x”. 4Ñ'ð",ð ð",ð ð",ð 
ð",ð ",ð ",ñ „Xð",ð ",ð ",r,   rZ   c                   óÊ  — e Zd ZdZedee         fd„¦   «         Zedefd„¦   «         Ze		 dde
eef         dedz  de
eef         fd„¦   «         Ze		 dde
eef         dedz  de
eef         fd	„¦   «         Ze	dddd
dœdedededee         dz  de
eef         dz  dedede
fd„¦   «         Ze	dddd
dœdedededee         dz  de
eef         dz  dedede
fd„¦   «         ZdS )ÚPairwiseStringDistanceEvalChainz6Compute string edit distances between two predictions.r   c                 ó
   — ddgS )r`   rb   Úprediction_br+   r7   s    r   rc   z*PairwiseStringDistanceEvalChain.input_keysH  s   € ð ˜nÐ-Ð-r,   c                 ó"   — d| j         j        › d�S )re   Ú	pairwise_rf   rg   r7   s    r   ri   z/PairwiseStringDistanceEvalChain.evaluation_nameQ  s   € ð :˜4œ=Ô.Ð9Ð9Ð9Ð9r,   Nrj   rk   c                 óJ   — d|                       |d         |d         ¦  «        iS )zìCompute the string distance between two predictions.

        Args:
            inputs: The input values.
            run_manager: The callback manager.

        Returns:
            The evaluation results containing the score.
        r6   rb   r‡   rn   ro   s      r   rp   z%PairwiseStringDistanceEvalChain._callZ  s-   € ð  �T×(Ò(¨°Ô)=¸vÀnÔ?UÑVÔVð
ð 	
r,   c              ƒ   óN   K  — d|                       |d         |d         ¦  «        iS )zûAsynchronously compute the string distance between two predictions.

        Args:
            inputs: The input values.
            run_manager: The callback manager.

        Returns:
            The evaluation results containing the score.
        r6   rb   r‡   rn   ro   s      r   rr   z&PairwiseStringDistanceEvalChain._acallm  s1   è è € ð  �T×(Ò(¨°Ô)=¸vÀnÔ?UÑVÔVð
ð 	
r,   F)rt   ru   rv   rw   rb   r‡   rt   ru   rv   rw   rx   c                óR   —  | ||dœ||||¬¦  «        }|                       |¦  «        S )aÿ  Evaluate the string distance between two predictions.

        Args:
            prediction: The first prediction string.
            prediction_b: The second prediction string.
            callbacks: The callbacks to use.
            tags: The tags to apply.
            metadata: The metadata to use.
            include_run_info: Whether to include run info in the output.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation results containing the score.
        ©rb   r‡   r{   r|   ©	r8   rb   r‡   rt   ru   rv   rw   rx   r:   s	            r   Ú_evaluate_string_pairsz6PairwiseStringDistanceEvalChain._evaluate_string_pairs€  sG   € ð4 �Ø",¸lÐKÐKØØØØ-ð
ñ 
ô 
ˆð ×#Ò# FÑ+Ô+Ð+r,   c             ‹   óv   K  — |                       ||dœ||||¬¦  «        ƒ d{V —†}|                      |¦  «        S )a  Asynchronously evaluate the string distance between two predictions.

        Args:
            prediction: The first prediction string.
            prediction_b: The second prediction string.
            callbacks: The callbacks to use.
            tags: The tags to apply.
            metadata: The metadata to use.
            include_run_info: Whether to include run info in the output.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation results containing the score.
        r�   r{   Nr€   rŽ   s	            r   Ú_aevaluate_string_pairsz7PairwiseStringDistanceEvalChain._aevaluate_string_pairs£  sk   è è € ð4 —z’zØ",¸lÐKÐKØØØØ-ð "ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð ×#Ò# FÑ+Ô+Ð+r,   rƒ   )r!   r"   r#   r$   rV   rF   rU   rc   ri   r   r<   r   r   rp   r   rr   r   rT   r�   r‘   r+   r,   r   r…   r…   E  s^  € € € € € Ø@Ð@àð.˜D œIð .ð .ð .ñ „Xð.ð ð: ð :ð :ð :ñ „Xð:ð ð :>ð
ð 
à�S˜#�X”ð
ð 0°$Ñ6ð
ð 
ˆc�3ˆhŒð	
ð 
ð 
ñ „Xð
ð$ ð ?Cð
ð 
à�S˜#�X”ð
ð 5°tÑ;ð
ð 
ˆc�3ˆhŒð	
ð 
ð 
ñ „Xð
ð$ ð  $Ø!%Ø*.Ø!&ð ,ð  ,ð  ,ð ð ,ð ð	 ,ð
 ð ,ð �3Œi˜$Ñð ,ð �s˜C�x”. 4Ñ'ð ,ð ð ,ð ð ,ð 
ð ,ð  ,ð  ,ñ „Xð ,ðD ð  $Ø!%Ø*.Ø!&ð ,ð  ,ð  ,ð ð ,ð ð	 ,ð
 ð ,ð �3Œi˜$Ñð ,ð �s˜C�x”. 4Ñ'ð ,ð ð ,ð ð ,ð 
ð ,ð  ,ð  ,ñ „Xð ,ð  ,ð  ,r,   r…   N)r$   Úcollections.abcr   Úenumr   Útypingr   Úlangchain_core.callbacksr   Ú langchain_core.callbacks.managerr   r   Úlangchain_core.utilsr	   Úpydanticr
   Útyping_extensionsr   Úlangchain_classic.chains.baser   Ú#langchain_classic.evaluation.schemar   r   Úlangchain_classic.schemar   r   rU   r   r.   rZ   r…   r+   r,   r   ú<module>r�      sá  ðØ @Ð @à $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .ðð ð ð ð ð ð ð ð *Ð )Ð )Ð )Ð )Ð )Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &à /Ð /Ð /Ð /Ð /Ð /Ø XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ ,Ð ,Ð ,Ð ,Ð ,Ð ,ð˜ð ð ð ð ð(ð ð ð ð �S˜$ñ ô ð ð(e!ð e!ð e!ð e!ð e!˜5ñ e!ô e!ð e!ðP],ð ],ð ],ð ],ð ],˜oÐ/Cñ ],ô ],ð ],ð@,ð ,ð ,ð ,ð ,Ð&=Ð?Sñ ,ô ,ð ,ð ,ð ,r,   