o
    h                     @   s.  d dl Zd dlZd dl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mZ dd
lmZmZmZ dd Zi dededededededededededede dej!dej"dej#dej$dej%i dej&dej'd ej(d!ej)d"ej*d#ej+d$ej,d%ej-d&ej.d'ed(e/d)e0d*e1d+e2d,e3d-e4d.e5i d/e6d0e7d1e8d2e9d3e:d4e;d5e<d6e=d7e>d8e?d9e@d:eAd;eBd<eCd=eDd>eEd?eFZGeG d@dA dAZHdBdCgZIdMdEdFZJdGdH ZKG dIdJ dJeZLG dKdL dLeZMdS )N    N)	dataclass)sqrt)Dict)hf_hub_downloadlist_spaces   )is_offline_mode   )LIST_SAFE_MODULESevaluate_python_code)TOOL_CONFIG_FILETOOL_MAPPINGToolc                  G   s   d S N )argsr   r   u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/transformers/agents/default_tools.pycustom_print      r   print
isinstancerangefloatintboolstrsetlistdicttupleroundceilfloorlogexpsincostanasinacosatanatan2degreesradianspowr   lensummaxminabs	enumeratezipreversedsortedallanymapfilterordchrnextiterdivmodcallablegetattrhasattrsetattr
issubclasstypec                   @   sF   e Zd ZU eed< eeef ed< eed< eed< eed< eed< dS )PreToolnameinputsoutput_typetaskdescriptionrepo_idN)__name__
__module____qualname__r   __annotations__r   rF   r   r   r   r   rG   Z   s   
 rG   zimage-transformationztext-to-imagehuggingface-toolsc           
   	   C   s   t  r
| d i S t|d}i }|D ]B}|j}t|tdd}t|dd}t|}W d    n1 s5w   Y  |	dd }	t
|	|d	 ||	|d
 |d d||d < q|S )Nz;You are in offline mode, so remote tools are not available.)authorspace)	repo_typezutf-8)encoding/rL   rI   rJ   )rK   rL   rM   rH   rI   rJ   rH   )r   infor   idr   r   openjsonloadsplitrG   )
loggerorganizationspacestools
space_inforM   resolved_config_filereaderconfigrK   r   r   r   get_remote_toolsj   s*   

	rg   c              	   C   s\   i }t d}|j}t D ]\}}t||}| }t|j|j|j	||j
d d||j< q|S )Ntransformers)rH   rI   rJ   rK   rL   rM   )	importlibimport_moduleagentsr   itemsrB   rG   rH   rI   rJ   rL   )r_   default_toolsmain_moduletools_module	task_nametool_class_name
tool_classtool_instancer   r   r   setup_default_tools   s   

	rt   c                       s6   e Zd ZdZdZdZdd fdd
Zdd	 Z  ZS )
PythonInterpreterToolpython_interpreterzRThis is a tool that evaluates python code. It can be used to perform calculations.stringN)authorized_importsc                   s\   |d u rt tt| _nt ttt|B | _ddd| ddi| _t j|i | d S )Ncoderw   zThe code snippet to evaluate. All variables used in this snippet must be defined in this same snippet, else you will get an error. This code can only import the following python libraries: .rF   rL   )r   r   r
   rx   rI   super__init__)selfrx   r   kwargs	__class__r   r   r}      s   	zPythonInterpreterTool.__init__c                 C   s   t t|t| jd}|S )N)static_toolsrx   )r   r   BASE_PYTHON_TOOLSrx   )r~   ry   outputr   r   r   forward   s   zPythonInterpreterTool.forward)	rN   rO   rP   rH   rL   rJ   r}   r   __classcell__r   r   r   r   ru      s    ru   c                   @   s.   e Zd ZdZdZddddiZdZdd Zd	S )
FinalAnswerToolfinal_answerz-Provides a final answer to the given problem.answerr9   zThe final answer to the problemr{   c                 C   s   |S r   r   )r~   r   r   r   r   r      r   zFinalAnswerTool.forwardN)rN   rO   rP   rH   rL   rI   rJ   r   r   r   r   r   r      s    r   )rR   )Nimportlib.utilri   r\   mathdataclassesr   r   typingr   huggingface_hubr   r   utilsr   rv   r
   r   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r   rG   "HUGGINGFACE_DEFAULT_TOOLS_FROM_HUBrg   rt   ru   r   r   r   r   r   <module>   s   	
 !"#$%&'()*+,-./01237

