U
    di
                     @   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                   @   s6   e Zd ZdZdZddddiZdZeedd	d
ZdS )DuckDuckGoSearchToolZ
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)r   returnc                 C   sB   zddl m} W n tk
r,   tdY nX | j|dd}|S )Nr   )DDGSzpYou must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`.   )Zmax_results)Zduckduckgo_searchr   ImportErrortext)selfr   r   results r   >/tmp/pip-unpacked-wheel-bm_b0l5e/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                   @   s6   e Zd ZdZdZddddiZdZeeddd	Zd
S )VisitWebpageToolZvisit_webpagezOVisits a wbepage at the given url and returns its content as a markdown string.urlr   z The url of the webpage to visit.r   )r   r   c              
   C   s   zddl m } W n tk
r,   tdY nX z4t|}|  ||j }tdd|}|W S  t	k
r } zdt
|  W Y S d }~X Y n4 tk
r } zdt
|  W Y S d }~X Y nX d S )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    responseZmarkdown_contenter   r   r   r   6   s     

"zVisitWebpageTool.forwardNr   r   r   r   r   r   +   s   r   )r%   r!   Zrequests.exceptionsr   Ztoolsr   r   r   r   r   r   r   <module>   s
   