
    sg
                     X    d dl Z d dlZd dlmZ ddlmZ  G d de      Z G d de      Zy)	    N)RequestException   )Toolc                   6    e Zd ZdZdZddddiZdZdedefd	Zy
)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                 t    	 ddl m}  |       j                  |d      }|S # t        $ r t        d      w xY w)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   resultss       M/var/www/html/venv/lib/python3.12/site-packages/transformers/agents/search.pyforwardzDuckDuckGoSearchTool.forward    sI    	.
 &++e+3  	 C 	s   " 7N	__name__
__module____qualname__namer   inputsoutput_typestrr        r   r   r      s6    D8K9WXYFKS S r$   r   c                   6    e Zd ZdZdZddddiZdZdedefdZy	)
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                    	 ddl m } 	 t        j                  |      }|j	                           ||j
                        j                         }t        j                  dd|      }|S # t        $ r t        d      w xY w# t        $ r}dt        |       cY d }~S d }~wt        $ r}dt        |       cY d }~S d }~ww xY 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es         r   r   zVisitWebpageTool.forward6   s    	/
	=||C(H%%'  +8==9??A  "vvi9IJ##  	v 	"   	;1#a&:: 	=3CF8<<	=s;   A' AA? 'A<?	B?BB?B?'B:4B?:B?Nr   r#   r$   r   r&   r&   +   s;    DcK=
F K=3 =3 =r$   r&   )r/   r+   requests.exceptionsr   toolsr   r   r&   r#   r$   r   <module>r7      s+   " 
  0 4 $"=t "=r$   