Team Ai
Apppublic

Goodguygregory93/ai-agents-certification-code

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

2���h���|�SSKJr SSKJr SSKJr SSKJr SSKJ	r	 SSK3Jr SSKrSSK
Jr SSKr"S	S45rg)�)�
AgentWorkflow)�HuggingFaceInferenceAPI)�FunctionTool)�Ollama)�Tools)�	RetrieverN)�load_dotenvc�j�\rSrSr\"5 SrS
S\S\4SjjrS\S\4SjrS\	\54S	jrS6rSr
g)�7BasicAgent�c���[[RRS-5 [R8R
S5n[R9R
S5n[R10R
S5nUc[S5eUc[S5eURXS9Ul	UR5UlUR5Ul
X lg)NzBasicAgent initialized.�	LLM_MODEL�11SYS_PROMPT�HF_TOKENz3Missing SYS_PROMPT: add SYS_PROMPT inside your .envz/Missing HF_TOKEN: add HF_TOKEN inside your .env)rr)�print�colorama�Fore�GREEN�os�environ�get�	Exception�_initialize_llm�	agent_llm�_initialize_agent_tools�agent_tools�_initialize_workflow�agent_work_flow�
system_prompt)�selfrrrs    �I/Users/gregwitt/Github/clones/ai-agents-certification-code/basic_agent.py�__init__�BasicAgent.__init__s���
�h�m�m�!�!�$=�=�>��J�J�N�N�;�/�	��Z�Z�^�^�L�1�12��:�:�>�>�*�-�����Q�R�R����M�N�N��-�-�	�-�U����7�7�9���#�8�8�:���'���question�returnc��d# �U(aZURSU3-nURRU5IShv�NnURRSR13nU$URRU5IShv�NnURRSR14nU$NqN+7f)a515the __call__ method is the method that is triggered when BasicAgent()16is called the `question` field is expected to be applied to the Agent's 17LlamaIndex Workflow and produce an LLM response 18 19the sys_prompt is defaulted to True and is found here: 20 21[GAIA HuggingFace Paper](https://huggingface.co/spaces/gaia-benchmark/leaderboard)22 23Args:24    question (str): the desired prompt that the user desires information25    sys_prompt (bool): defaults to True as the GAIA specifications prompt is supplied in the study26Returns:27    response (str): response from the LLM 28z QUESTION: Nr)rr�run�response�blocks�text)r r%�29sys_prompt�prompt�agent_outputr)s      r!�__call__�BasicAgent.__call__!s���� ��'�'�K��z�*B�B�F�!%�!5�!5�!9�!9�&�!A�A�L�#�,�,�3�3�A�6�;�;�H���	"&�!5�!5�!9�!9�(�!C�C�L�#�,�,�3�3�A�6�;�;�H���B�D�s"�8B0�B,�AB0�B.�*B0�.B0rrc�~�[[RRS-5 [S5 [	UUSS9nU$)z�30initialize the llm brain of the Agent using an Ollama installed31model. Returns the Ollama object32 33Args:34    LLM_MODEL (str): provider model name ex: "llama3.2:latest"35 36Returns:37    llm: returns the HuggingFaceInferenceAPI Model38u&🧠 initializing an LLM for the Agentz---------------�auto)�39model_name�token�provider)rrr�YELLOWr)r rr�llms    r!r�BasicAgent._initialize_llm<s?��	�h�m�m�"�"�%M�M�N�
�f�
�&� ������40r$c�T�/n[5RnURU5 U$)a 41returns the FunctionalTools from the Tool class calling the42tool_belt and collecting the tools into a list. also loads43the Retriever tool `similar_question_tool` for question querying44 45Args:46    None47Returns:48    found_tools (list[FunctionTool]): the tools initiated from the Tool agent49)r�similar_question_tool�append)r �found_toolsr:s   r!r�"BasicAgent._initialize_agent_toolsTs0����!*�� A� A�����0�1�50�r$c�X�[R"URURS9nU$)af51creates the BasicAgent Workflow for the agent that will leverage the52Tools `agent_tools` and the `agent_llm` from the HuggingFaceInterfaceAPI53 54Args:                55    None56Returns:57    basic_agent_workflow (AgentWorkflow): leverages the agent_tools, and agent_llm to create a workflow58                                        that will create the workflow59)r7)r�from_tools_or_functionsrr)r �basic_agent_workflows  r!r�BasicAgent._initialize_workflowks-�� -�D�D�� � ��N�N� ��60$�#r$)rrrrN)T)�__name__�61__module__�__qualname__�__firstlineno__r	r"�strr/r�listrrr�__static_attributes__�r$r!rrsH���M�(�&�s����6�����0��l�);��.$r$r)�llama_index.core.agent.workflowr� llama_index.llms.huggingface_apir�llama_index.core.toolsr�llama_index.llms.ollamar�toolsr�	retrieverrr�dotenvr	rrrIr$r!�<module>rQs,��9�D�/�*�����	�p$�p$r$