
    g
                     f    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dS )	    N)RequestException   )Toolc                   8    e Zd ZdZdZddddiZdZdedef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                     	 ddl m} n# t          $ r t          d          w xY w |                                |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   resultss       V/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/agents/search.pyforwardzDuckDuckGoSearchTool.forward    sq    	....... 	 	 	 C  	 $&&++e+33s   	 #N	__name__
__module____qualname__namer   inputsoutput_typestrr        r   r   r      sZ        D8K9WXXYFKS S      r$   r   c                   8    e Zd ZdZdZddddiZdZdedefdZd	S )
VisitWebpageTool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   c                    	 ddl m } n# t          $ r t          d          w xY w	 t          j        |          }|                                  ||j                                                  }t          j        dd|          }|S # 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*   	/////// 	 	 	v  		=|C((H%%'''  +{8=99??AA  "vi9IJJ## 	; 	; 	;:#a&&:::::::: 	= 	= 	=<CFF<<<<<<<<	=s8   	 #A!B	 	
CB*$C*C7CCCNr   r#   r$   r   r&   r&   +   sa        DcK=
 
F K=3 =3 = = = = = =r$   r&   )r/   r+   requests.exceptionsr   toolsr   r   r&   r#   r$   r   <module>r7      s   " 
			  0 0 0 0 0 0          4   $"= "= "= "= "=t "= "= "= "= "=r$   