Team Ai
Apppublic

Goodguygregory93/ai-agents-certification-code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
tools.cpython-313.pyc70 linesDownload Raw Back to __pycache__
1�

2c��hQ��l�SSKJr SSKJr SSKJr SSKJr SSKrSSK	r	SSK3Jr SSKr"SS5r
g)	�)�DuckDuckGoSearchToolSpec)�FunctionTool)�WikipediaReader)�YouTubeTranscriptApiN)�
BeautifulSoupc�J�\rSrSrSrSSjrSrS\4SjrS\4Sjr	S	r4S5rg)
�Tools�!ar6Tools class which holds all of the the tools the Basic Agent will7leverage to answer the GAIA Challenge8 9Included Tools: 10 11* duck_duck_go_search_tool: allows for searching Duck Duck Go for answers *see create_duck_duck_go_tool for usage example*12* wikipedia_search_tool: allows for searching wikipedia for specific details about a subject matter, leveraging wikipedia13 14c��XlUR5Ul[R"UR155Ul[R"UR5Ul[R"UR5UlU(a}[[RRS-5 [[RRS-5 [[RRS-5 [S5 URUR16URUR/Ulg)Nu/✅ 📖 Wikipedia Search tool has been createdu;✅ 📹 Youtube Transcription Search tool has been createdu6✅ 💻 📰 Wired Top Articles tool has been createdz---------------)
�status_updates�create_duck_duck_go_tool�duck_duck_go_search_toolr�
from_defaults�wikipedia_search_tool�youtube_transcription_tool�top_wired_articles_tool�print�colorama�Fore�YELLOW�	tool_belt)�selfrs  �C/Users/gregwitt/Github/clones/ai-agents-certification-code/tools.py�__init__�Tools.__init__-s���,��(,�(E�(E�(G��%�%1�%?�%?��@Z�@Z�%[��"�*6�*D�*D�T�Ed�Ed�*e��'�'3�'A�'A�$�B^�B^�'_��$���(�-�-�&�&�)Z�Z�[��(�-�-�&�&�+f�g�h��(�-�-�&�&�+a�b�c��&�M��7�7��9S�9S�UY�Ut�Ut��4�4�6���c���[5n[R"UR5nUR(a&[[RRS-5 U$)a�17creates the DuckDuckGo Search tool from LlamaIndex18and returns the tool for later use19 20Example usage:21 22```python23response = self.duck_duck_go_search_tool("Who is the silver robot from daft punk?")24 25print(response.raw_output[-1]['body'])26```27 28[Tool Documentation](https://llamahub.ai/l/tools/llama-index-tools-duckduckgo?from=)29 30Args: 31    self : class instance32Returns:33    search_tool (FunctionTool): represents the FunctionTool Spec for DuckDuckGoSearch34u+✅ 🦆 Duck Duck Go tool has been created)	rrr�duckduckgo_full_searchrrrrr)r�	tool_spec�search_tools   rr
�Tools.create_duck_duck_go_tool=sI��*-�.�	�"�0�0��1Q�1Q�R������(�-�-�&�&�+V�W�X��r�queryc�:�[5nURU/S9nU$)a�35creates a Wikipedia Search FunctionTool for searching wikipedia articles for specific pages36the details from the specified query37 38[Tool Documentation](https://llamahub.ai/l/readers/llama-index-readers-wikipedia?from=)39 40Args: 41    self: class instance 42    query (str): the specific article in question to be searched in wikipedia.43Returns: 44    found_document : the response from the Wikipedia Reader which is the found article 45)�pages)r�	load_data)rr"�wiki_reader�found_documents    rr�Tools.wikipedia_search_tool\s'��&�'��$�.�.�e�W�.�=���r�46video_linkc��[R"S5nURU5nUcgSnUR5R	S5Sn[5nUR
US/S9nUHnXHRS--
nM U$)	aY47checks if the supplied video(s) is in fact a valid youtube video and then proceeds to load the entire transcription 48of the provided youtube video for quick searching and relevance querying for your llm.49leverages the `YoutubeTranscriptionReader` from LlamaIndex to provide a string response of the 50youtube video in question. 51 52 53[Tool Documentation](https://pypi.org/project/youtube-transcript-api/)54 55Args: 56    video_link (list[str]): videos or video in question that you desire information about.57Returns:58    transcript_text: the converted youtube video's audio transcription content in a string59zv=(\w+)z0You haven't provided a legitimate youtube video.��=�zen-US)�video_id�	languages� )�re�compile�search�group�splitr�fetch�text)	rr)�videoIdRegex�mo�transcript_text�videoId�ytt_api�fetched_transcript�snippets	         rr� Tools.youtube_transcription_toolps��� �z�z�*�-��
�
 �
 ��
,��
�:�E� �O��h�h�j�&�&�s�+�A�.�G�*�,�G�!(����G�9��!U��-���<�<�#�#5�5��.�#�"rc���[R"5nSnURU5n[URS5nURSS[R"S505n0nUH�nURS5RnURS5Rn	URS5RSn60URSS[R"S	505RnM� [$)61z'62 63 64Returns:65    top_articles (dict): 66 67z&https://www.wired.com/about/rss-feeds/zhtml.parser�div�class�SummaryItemContent�span�a�href�68BylineName)�requests�Session�getrr7�find_allr1r2�find�attrs�popular_wired_unordered_list)r�session�	wired_url�rss_feed_page_resp�soup�popular_wired_popular_li_list�found_articles�69article_li�category�
article_title�article_link�article_authors            rr�Tools.top_wired_articles_tool�s����"�"�$��<�	�$�[�[��3���/�4�4�m�D��)-�
�
�e�g�r�z�z�Rf�Gg�=h�(i�%���7�J�!���v�.�3�3�H�&�O�O�C�0�5�5�M�%�?�?�3�/�5�5�f�=�L�'�_�_�V�g�r�z�z�,�?W�5X�Y�^�^�N�8�,�+r)rrrrrrN)F)�__name__�70__module__�__qualname__�__firstlineno__�__doc__rr
�strrrr�__static_attributes__�rrr	r	!s/��	�6� �>�3��(!#�S�!#�F,rr	)�llama_index.tools.duckduckgor�llama_index.core.toolsr�llama_index.readers.wikipediar�youtube_transcript_apirr1rH�bs4rrr	rbrr�<module>rhs)��A�/�9�7�	����0O,�O,r