§
    \zni'  ã                   óÜ   — d dl Z d dlZd dlmZ d dlmZmZmZ  G d„ de¦  «        Z	dde
dee
ef         fd	„Zd
e j        dee
ef         dee
ef         fd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )é    N)ÚMapping)ÚAnyÚCallableÚDictc                   ó   — e Zd ZdZdS )ÚInterpretorErrorz†
    An error raised when the interpretor cannot evaluate a Python expression, due to syntax error or unsupported
    operations.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú…/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/tools/python_interpreter.pyr   r      s   € € € € € ðð ð
 	€Dr   r   FÚcodeÚtoolsc                 ór  — 	 t          j        | ¦  «        }n(# t          $ r}t          d|¦  «         Y d}~dS d}~ww xY w|€i }d}t	          |j        ¦  «        D ]]\  }}	 t          |||¦  «        }	nA# t          $ r4}d|› d�}
|r
|
d|› d�z  }
n|
d|› �z  }
t          |
¦  «         Y d}~ nd}~ww xY w|	�|	}Œ^|S )a@  
    Evaluate a python expression using the content of the variables stored in a state and only evaluating a given set
    of functions.

    This function will recurse through the nodes of the tree provided.

    Args:
        code (`str`):
            The code to evaluate.
        tools (`Dict[str, Callable]`):
            The functions that may be called during the evaluation. Any call to another function will fail with an
            `InterpretorError`.
        state (`Dict[str, Any]`):
            A dictionary mapping variable names to values. The `state` should contain the initial inputs but will be
            updated by this function to contain all variables as they are evaluated.
        chat_mode (`bool`, *optional*, defaults to `False`):
            Whether or not the function is called from `Agent.chat`.
    z.The code generated by the agent is not valid.
Nz'Evaluation of the code stopped at line z. before the end because of the following errorzY. Copy paste the following error message and send it back to the agent:
I get an error: 'ú'z:
)ÚastÚparseÚSyntaxErrorÚprintÚ	enumerateÚbodyÚevaluate_astr   )r   r   ÚstateÚ	chat_modeÚ
expressionÚeÚresultÚidxÚnodeÚline_resultÚmsgs              r   Úevaluater$       s(  € ð&Ý”Y˜t‘_”_ˆ
ˆ
øÝð ð ð ÝÐ?ÀÑCÔCÐCØˆˆˆˆˆøøøøðøøøð €}ØˆØ€FÝ˜zœÑ/Ô/ð !ð !‰	ˆˆTð	Ý& t¨U°EÑ:Ô:ˆKˆKøÝð 		ð 		ð 		Øo¸CÐoÐoÐoˆCØð !ØØuÐqrÐuÐuÐuñ��ð �y˜Q�y�yÑ �Ý�#‰JŒJˆJØˆEˆEˆEˆEˆEøøøøð		øøøð Ð"Ø ˆFøà€Ms(   ‚ —
<¡7·<ÁA1Á1
B/Á;)B*Â*B/r   r   c                 ój  ‡‡— t          | t          j        ¦  «        rt          | ‰‰¦  «        S t          | t          j        ¦  «        rt          | ‰‰¦  «        S t          | t          j        ¦  «        r| j        S t          | t          j        ¦  «        rEˆˆfd„| j	        D ¦   «         }ˆˆfd„| j
        D ¦   «         }t          t          ||¦  «        ¦  «        S t          | t          j        ¦  «        rt          | j        ‰‰¦  «        S t          | t          j        ¦  «        rt!          | ‰‰¦  «        S t          | t          j        ¦  «        rt          | j        ‰‰¦  «        S t          | t          j        ¦  «        rt'          | ‰‰¦  «        S t)          t          d¦  «        r0t          | t          j        ¦  «        rt          | j        ‰‰¦  «        S t          | t          j        ¦  «        r'd                     ˆˆfd„| j
        D ¦   «         ¦  «        S t          | t          j        ¦  «        rˆˆfd„| j        D ¦   «         S t          | t          j        ¦  «        rt7          | ‰‰¦  «        S t          | t          j        ¦  «        rt;          | ‰‰¦  «        S t=          | j        j         › d�¦  «        ‚)a³  
    Evaluate an absract syntax tree using the content of the variables stored in a state and only evaluating a given
    set of functions.

    This function will recurse trough the nodes of the tree provided.

    Args:
        expression (`ast.AST`):
            The code to evaluate, as an abastract syntax tree.
        state (`Dict[str, Any]`):
            A dictionary mapping variable names to values. The `state` is updated if need be when the evaluation
            encounters assignements.
        tools (`Dict[str, Callable]`):
            The functions that may be called during the evaluation. Any call to another function will fail with an
            `InterpretorError`.
    c                 ó2   •— g | ]}t          |‰‰¦  «        ‘ŒS r   ©r   )Ú.0Úkr   r   s     €€r   ú
<listcomp>z evaluate_ast.<locals>.<listcomp>k   s%   ø€ ÐGÐGÐG°!•˜Q  uÑ-Ô-ÐGÐGÐGr   c                 ó2   •— g | ]}t          |‰‰¦  «        ‘ŒS r   r'   ©r(   Úvr   r   s     €€r   r*   z evaluate_ast.<locals>.<listcomp>l   s%   ø€ ÐKÐKÐK°A•,˜q %¨Ñ/Ô/ÐKÐKÐKr   ÚIndexÚ c           	      óL   •— g | ] }t          t          |‰‰¦  «        ¦  «        ‘Œ!S r   )Ústrr   r,   s     €€r   r*   z evaluate_ast.<locals>.<listcomp>}   s-   ø€ ÐVÐVÐV¸q��L¨¨E°5Ñ9Ô9Ñ:Ô:ÐVÐVÐVr   c                 ó2   •— g | ]}t          |‰‰¦  «        ‘ŒS r   r'   )r(   Úeltr   r   s     €€r   r*   z evaluate_ast.<locals>.<listcomp>€   s%   ø€ ÐKÐKÐK°C•˜S %¨Ñ/Ô/ÐKÐKÐKr   z is not supported.)!Ú
isinstancer   ÚAssignÚevaluate_assignÚCallÚevaluate_callÚConstantÚvaluer   ÚkeysÚvaluesÚdictÚzipÚExprr   ÚForÚevaluate_forÚFormattedValueÚIfÚevaluate_ifÚhasattrr.   Ú	JoinedStrÚjoinÚListÚeltsÚNameÚevaluate_nameÚ	SubscriptÚevaluate_subscriptr   Ú	__class__r	   )r   r   r   r;   r<   s    ``  r   r   r   N   s   øø€ õ" �*�cœjÑ)Ô)ð *Uõ ˜z¨5°%Ñ8Ô8Ð8Ý	�J¥¤Ñ	)Ô	)ð &Uå˜Z¨°Ñ6Ô6Ð6Ý	�J¥¤Ñ	-Ô	-ð #UàÔÐÝ	�J¥¤Ñ	)Ô	)ð  UàGÐGÐGÐGÐG°z´ÐGÑGÔGˆØKÐKÐKÐKÐK¸Ô9JÐKÑKÔKˆÝ•C˜˜fÑ%Ô%Ñ&Ô&Ð&Ý	�J¥¤Ñ	)Ô	)ð Uå˜JÔ,¨e°UÑ;Ô;Ð;Ý	�J¥¤Ñ	(Ô	(ð Uå˜J¨¨uÑ5Ô5Ð5Ý	�J¥Ô 2Ñ	3Ô	3ð Uå˜JÔ,¨e°UÑ;Ô;Ð;Ý	�J¥¤Ñ	'Ô	'ð Uå˜: u¨eÑ4Ô4Ð4Ý	•�gÑ	Ô	ð U¥:¨j½#¼)Ñ#DÔ#Dð UÝ˜JÔ,¨e°UÑ;Ô;Ð;Ý	�J¥¤Ñ	.Ô	.ð UØ�wŠwÐVÐVÐVÐVÐVÀJÔDUÐVÑVÔVÑWÔWÐWÝ	�J¥¤Ñ	)Ô	)ð UàKÐKÐKÐKÐK¸:¼?ÐKÑKÔKÐKÝ	�J¥¤Ñ	)Ô	)ð Uå˜Z¨°Ñ6Ô6Ð6Ý	�J¥¤Ñ	.Ô	.ð Uå! *¨e°UÑ;Ô;Ð;õ  *Ô"6Ô"?ÐSÐSÐSÑTÔTÐTr   c                 óh  — | j         }t          | j        ||¦  «        }t          |¦  «        dk    r|||d         j        <   npt          |¦  «        t          |¦  «        k    r0t          dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚t          ||¦  «        D ]\  }}|||j        <   Œ|S )Né   r   z	Expected z values but got ú.)Útargetsr   r:   ÚlenÚidr   r>   )Úassignr   r   Ú	var_namesr   Úvar_nameÚrs          r   r6   r6   Œ   s·   € Ø”€IÝ˜&œ,¨¨uÑ5Ô5€Få
ˆ9�~„~˜ÒÐØ!'ˆˆi˜ŒlŒoÑÐåˆv‰;Œ;�#˜i™.œ.Ò(Ð(Ý"Ð#]­s°9©~¬~Ð#]Ð#]ÍsÐSYÉ{Ì{Ð#]Ð#]Ð#]Ñ^Ô^Ð^Ý˜y¨&Ñ1Ô1ð 	#ð 	#‰KˆH�aØ!"ˆE�(”+ÑÐØ€Mr   c                 óh  ‡‡— t          | j        t          j        ¦  «        s-t	          d| j        › dt          | j        ¦  «        › d�¦  «        ‚| j        j        }|‰vrt	          d| j        j        › d�¦  «        ‚‰|         }ˆˆfd„| j        D ¦   «         }ˆˆfd„| j        D ¦   «         } ||i |¤ŽS )NzZIt is not permitted to evaluate other functions than the provided tools (tried to execute z	 of type rQ   z).c                 ó2   •— g | ]}t          |‰‰¦  «        ‘ŒS r   r'   )r(   Úargr   r   s     €€r   r*   z!evaluate_call.<locals>.<listcomp>¨   s%   ø€ ÐAÐAÐA°�L˜˜e UÑ+Ô+ÐAÐAÐAr   c                 óH   •— i | ]}|j         t          |j        ‰‰¦  «        “ŒS r   )r[   r   r:   )r(   Úkeywordr   r   s     €€r   ú
<dictcomp>z!evaluate_call.<locals>.<dictcomp>©   s+   ø€ ÐbÐbÐbÈˆgŒk�<¨¬°u¸eÑDÔDÐbÐbÐbr   )	r4   Úfuncr   rJ   r   ÚtyperT   ÚargsÚkeywords)Úcallr   r   Ú	func_namer_   ra   Úkwargss    ``    r   r8   r8   š   s÷   øø€ Ý�d”i¥¤Ñ*Ô*ð 
Ýð'ÐimÔirð 'ð 'Ý˜œ‘O”Oð'ð 'ð 'ñ
ô 
ð 	
ð ”	”€IØ˜ÐÐÝØyÐimÔirÔiuÐyÐyÐyñ
ô 
ð 	
ð �Ô€DàAÐAÐAÐAÐA°t´yÐAÑAÔA€DØbÐbÐbÐbÐbÐTXÔTaÐbÑbÔb€FØˆ4�Ð ˜Ð Ð Ð r   c                 óþ  — t          | j        ||¦  «        }t          | j        ||¦  «        }t          |t          t
          f¦  «        r|t          |¦  «                 S ||v r||         S t          |t          ¦  «        rjt          |t          ¦  «        rUt          j
        |t	          |                     ¦   «         ¦  «        ¦  «        }t          |¦  «        dk    r||d                  S t          d|› d|› d�¦  «        ‚)Nr   zCould not index z with 'z'.)r   Úslicer:   r4   ÚlistÚtupleÚintr1   r   ÚdifflibÚget_close_matchesr;   rS   r   )Ú	subscriptr   r   Úindexr:   Úclose_matchess         r   rM   rM   ­   sì   € Ý˜œ¨%°Ñ7Ô7€EÝ˜œ¨%°Ñ7Ô7€EÝ�%�$¥˜Ñ'Ô'ð !Ø•S˜‘Z”ZÔ Ð Ø�€~€~Ø�UŒ|ÐÝ�%�ÑÔð +¥*¨UµGÑ"<Ô"<ð +ÝÔ1°%½¸e¿jºj¹l¼lÑ9KÔ9KÑLÔLˆÝˆ}ÑÔ Ò!Ð!Ø˜ qÔ)Ô*Ð*å
ÐE¨eÐEÐE¸EÐEÐEÐEÑ
FÔ
FÐFr   c                 ó  — | j         |v r|| j                  S t          j        | j         t          |                     ¦   «         ¦  «        ¦  «        }t          |¦  «        dk    r||d                  S t          d| j         › d�¦  «        ‚)Nr   zThe variable `z` is not defined.)rT   rk   rl   rh   r;   rS   r   )Únamer   r   ro   s       r   rK   rK   ¼   s~   € Ø„w�%ÐÐØ�T”WŒ~ÐÝÔ-¨d¬gµt¸E¿JºJ¹L¼LÑ7IÔ7IÑJÔJ€MÝ
ˆ=ÑÔ˜AÒÐØ�] 1Ô%Ô&Ð&Ý
ÐF¨D¬GÐFÐFÐFÑ
GÔ
GÐGr   c                 ób  — t          | j        ¦  «        dk    rt          d¦  «        ‚t          | j        ||¦  «        }| j        d         }t          | j        d         ||¦  «        }t          |t          j        ¦  «        r||k    S t          |t          j	        ¦  «        r||k    S t          |t          j
        ¦  «        r||k     S t          |t          j        ¦  «        r||k    S t          |t          j        ¦  «        r||k    S t          |t          j        ¦  «        r||k    S t          |t          j        ¦  «        r||u S t          |t          j        ¦  «        r||uS t          |t          j        ¦  «        r||v S t          |t          j        ¦  «        r||vS t          d|› �¦  «        ‚)NrP   z2Cannot evaluate conditions with multiple operatorsr   zOperator not supported: )rS   Úopsr   r   ÚleftÚcomparatorsr4   r   ÚEqÚNotEqÚLtÚLtEÚGtÚGtEÚIsÚIsNotÚInÚNotIn)Ú	conditionr   r   rt   Ú
comparatorÚrights         r   Úevaluate_conditionrƒ   Å   s­  € Ý
ˆ9Œ=ÑÔ˜AÒÐÝÐSÑTÔTÐTå˜	œ¨¨uÑ5Ô5€DØ”˜qÔ!€JÝ˜Ô.¨qÔ1°5¸%Ñ@Ô@€Eå�*�cœfÑ%Ô%ð HØ�uŠ}ÐÝ	�J¥¤	Ñ	*Ô	*ð HØ�uŠ}ÐÝ	�J¥¤Ñ	'Ô	'ð HØ�eŠ|ÐÝ	�J¥¤Ñ	(Ô	(ð HØ�uŠ}ÐÝ	�J¥¤Ñ	'Ô	'ð HØ�eŠ|ÐÝ	�J¥¤Ñ	(Ô	(ð HØ�uŠ}ÐÝ	�J¥¤Ñ	'Ô	'ð 	HØ�uˆ}ÐÝ	�J¥¤	Ñ	*Ô	*ð HØ˜5Ð Ð Ý	�J¥¤Ñ	'Ô	'ð HØ�uˆ}ÐÝ	�J¥¤	Ñ	*Ô	*ð HØ˜5Ð Ð åÐF¸*ÐFÐFÑGÔGÐGr   c                 ó´   — d }t          | j        ||¦  «        r | j        D ]}t          |||¦  «        }|�|}Œn| j        D ]}t          |||¦  «        }|�|}Œ|S ©N)rƒ   Útestr   r   Úorelse)Úif_statementr   r   r   Úliner"   s         r   rD   rD   å   sˆ   € Ø€FÝ˜,Ô+¨U°EÑ:Ô:ð 	%Ø Ô%ð 	%ð 	%ˆDÝ& t¨U°EÑ:Ô:ˆKØÐ&Ø$�øð	%ð
 !Ô'ð 	%ð 	%ˆDÝ& t¨U°EÑ:Ô:ˆKØÐ&Ø$�øØ€Mr   c                 óœ   — d }t          | j        ||¦  «        }|D ]0}||| j        j        <   | j        D ]}t          |||¦  «        }|�|}ŒŒ1|S r…   )r   ÚiterÚtargetrT   r   )Úfor_loopr   r   r   ÚiteratorÚcounterr   r"   s           r   rA   rA   ô   sr   € Ø€FÝ˜HœM¨5°%Ñ8Ô8€HØð %ð %ˆØ$+ˆˆhŒoÔ Ñ!Ø"œ-ð 	%ð 	%ˆJÝ& z°5¸%Ñ@Ô@ˆKØÐ&Ø$�øð	%ð €Mr   )NF)r   rk   Úcollections.abcr   Útypingr   r   r   Ú
ValueErrorr   r1   r$   ÚASTr   r6   r8   rM   rK   rƒ   rD   rA   r   r   r   ú<module>r”      se  ðð" €
€
€
Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &ð	ð 	ð 	ð 	ð 	�zñ 	ô 	ð 	ð+ð +�3ð +˜t C¨ MÔ2ð +ð +ð +ð +ð\;U˜SœWð ;U¨T°#°s°(¬^ð ;UÀDÈÈhÈÔDWð ;Uð ;Uð ;Uð ;Uð|ð ð ð!ð !ð !ð&Gð Gð GðHð Hð HðHð Hð Hð@ð ð ð	ð 	ð 	ð 	ð 	r   