
    Ng                     R    d Z ddlZddlmZ ddlmZ ddlmZ  G 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                   h    e Zd ZU dZdZeed<   dZeed<   dededefd	Z		 ddede
e         def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                     ddl m}  |||                                          }t          j        |          }d |d         D             }t          |          S )Nr   )YoutubeSearchc                 $    g | ]}d |d         z   S )zhttps://www.youtube.com
url_suffix ).0videos     d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/youtube/search.py
<listcomp>z-YouTubeSearchTool._search.<locals>.<listcomp>$   s0     
 
 
@E%l(;;
 
 
    videos)r   r   to_jsonjsonloadsstr)selfr   r   r   resultsdataurl_suffix_lists          r   _searchzYouTubeSearchTool._search   sr    000000-44<<>>z'""
 
IMh
 
 
 ?###r   Nqueryrun_managerc                     |                     d          }|d         }t          |          dk    rt          |d                   }nd}|                     ||          S )zUse the tool.,r         )splitlenintr!   )r   r"   r#   valuesr   r   s         r   _runzYouTubeSearchTool._run)   sW     S!!v;;??fQi..KKK||FK000r   )N)__name__
__module____qualname____doc__r	   r   __annotations__r
   r*   r!   r   r   r,   r   r   r   r   r      s         $$ D#   	A    $c $ $ $ $ $ $ <@1 11 781 
	1 1 1 1 1 1r   r   )	r0   r   typingr   langchain_core.callbacksr   langchain_core.toolsr   r   r   r   r   <module>r5      s   	 	        > > > > > > ) ) ) ) ) )"1 "1 "1 "1 "1 "1 "1 "1 "1 "1r   