o
    h
                     @   sL   d dl Z d dlZd dlmZ ddlmZ G dd deZG dd deZdS )	    N)RequestException   )Toolc                   @   s8   e Zd ZdZdZddddiZdZdedefd	d
ZdS )DuckDuckGoSearchTool
web_searchzPerform a web search based on your query (think a Google search) then returns the top search results as a list of dict elements.
    Each result has keys 'title', 'href' and 'body'.querystringzThe search query to perform.typedescriptionanyreturnc                 C   s<   zddl m} W n ty   tdw | j|dd}|S )Nr   )DDGSzpYou must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`.   )max_results)duckduckgo_searchr   ImportErrortext)selfr   r   results r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/transformers/agents/search.pyforward    s   zDuckDuckGoSearchTool.forwardN	__name__
__module____qualname__namer   inputsoutput_typestrr   r   r   r   r   r      s    r   c                   @   s8   e Zd ZdZdZddddiZdZdedefdd	Zd
S )VisitWebpageToolvisit_webpagezOVisits a webpage at the given url and returns its content as a markdown string.urlr   z The url of the webpage to visit.r	   r   c              
   C   s   zddl m } W n ty   tdw zt|}|  ||j }tdd|}|W S  t	yG } zdt
| W  Y d }~S d }~w ty_ } zdt
| W  Y d }~S d }~ww )Nr   )markdownifyzdYou must install package `markdownify` to run this tool: for instance run `pip install markdownify`.z\n{3,}z

zError fetching the webpage: zAn unexpected error occurred: )r$   r   requestsgetraise_for_statusr   stripresubr   r    	Exception)r   r#   r$   responsemarkdown_contenter   r   r   r   6   s(   
zVisitWebpageTool.forwardNr   r   r   r   r   r!   +   s    r!   )r)   r%   requests.exceptionsr   toolsr   r   r!   r   r   r   r   <module>   s   