a
    bŠÝgÕ  ã                   @   sD   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ deƒZdS )ae  
Adapted from https://github.com/venuv/langchain_yt_tools

CustomYTSearchTool searches YouTube videos related to a person
and returns a specified number of video URLs.
Input to this tool should be a comma separated list,
 - the first part contains a person name
 - and the second(optional) a number that is the
    maximum number of video results to return
é    N)ÚOptional)ÚCallbackManagerForToolRun)ÚBaseToolc                   @   sT   e Zd ZU dZdZeed< dZeed< eeedœdd„Z	dee
e ed
œdd„Zd	S )ÚYouTubeSearchToolzTool that queries YouTube.Úyoutube_searchÚnamea  search for youtube videos associated with a person. the input to this tool should be a comma separated list, the first part contains a person name and the second a number that is the maximum number of video results to return aka num_results. the second part is optionalÚdescription)ÚpersonÚnum_resultsÚreturnc                 C   s>   ddl m} |||ƒ ¡ }t |¡}dd„ |d D ƒ}t|ƒS )Nr   )ÚYoutubeSearchc                 S   s   g | ]}d |d  ‘qS )zhttps://www.youtube.comZ
url_suffix© )Ú.0Zvideor   r   úv/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/youtube/search.pyÚ
<listcomp>$   s   z-YouTubeSearchTool._search.<locals>.<listcomp>Zvideos)r   r   Úto_jsonÚjsonÚloadsÚstr)Úselfr	   r
   r   ÚresultsÚdataZurl_suffix_listr   r   r   Ú_search   s    
ÿzYouTubeSearchTool._searchN)ÚqueryÚrun_managerr   c                 C   s<   |  d¡}|d }t|ƒdkr,t|d ƒ}nd}|  ||¡S )zUse the tool.ú,r   é   é   )ÚsplitÚlenÚintr   )r   r   r   Úvaluesr	   r
   r   r   r   Ú_run)   s    
zYouTubeSearchTool._run)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r    r   r   r   r"   r   r   r   r   r      s   
ÿ
 ýür   )	r&   r   Útypingr   Zlangchain_core.callbacksr   Zlangchain_core.toolsr   r   r   r   r   r   Ú<module>   s
   