o
    i                  
   @   s   d dl Z d dlmZmZ d dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZ zzd dlmZ W n ey@   d dlmZ Y nw W n eyS Z zededZ[ww dZG d	d
 d
e
Zeee ZeG dd dZddedB dedB fddZdS )    N)KW_ONLY	dataclass)TypeAdapter)Any	TypedDict)Tool)DDGSu   Please install `ddgs` to use the DuckDuckGo search tool, you can use the `duckduckgo` optional group — `pip install "pydantic-ai-slim[duckduckgo]"`)duckduckgo_search_toolc                   @   s.   e Zd ZU dZeed< 	 eed< 	 eed< dS )DuckDuckGoResultzA DuckDuckGo search result.titlehrefbodyN)__name__
__module____qualname____doc__str__annotations__ r   r   i/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/common_tools/duckduckgo.pyr
      s   
 r
   c                   @   sH   e Zd ZU dZeed< 	 eed< edB ed< 	 dede	e
 fdd	ZdS )
DuckDuckGoSearchToolzThe DuckDuckGo search tool.client_Nmax_resultsqueryreturnc                    s4   t j| jj| jd}tj||I dH }t	|S )zSearches DuckDuckGo for the given query and returns the results.

        Args:
            query: The query to search for.

        Returns:
            The search results.
        )r   N)
	functoolspartialr   textr   anyio	to_threadrun_syncduckduckgo_tavalidate_python)selfr   searchresultsr   r   r   __call__3   s   	
zDuckDuckGoSearchTool.__call__)r   r   r   r   r   r   r   intr   listr
   r'   r   r   r   r   r   '   s   
 r   duckduckgo_clientr   c                 C   s"   t t t| pt |djdddS )zCreates a DuckDuckGo search tool.

    Args:
        duckduckgo_client: The DuckDuckGo search client.
        max_results: The maximum number of results. If None, returns results only from the first response.
    )r   r   duckduckgo_searchz@Searches DuckDuckGo for the given query and returns the results.)namedescription)r   r   r   r   r'   )r*   r   r   r   r   r	   A   s
   r	   )NN)r   dataclassesr   r   r   anyio.to_threadpydanticr   typing_extensionsr   r   pydantic_ai.toolsr   	ddgs.ddgsr   ImportErrorr+   _import_error__all__r
   r)   r"   r   r(   r	   r   r   r   r   <module>   s8     