{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/soumyadip/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020\n", " warnings.warn(\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from llama_index.core.agent import ReActAgent\n", "from llama_index.llms.groq import Groq\n", "from llama_index.core.llms import ChatMessage\n", "from llama_index.core.tools import BaseTool, FunctionTool\n", "from llama_index.tools.tavily_research.base import TavilyToolSpec\n", "import os\n", "from dotenv import load_dotenv\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "search = TavilyToolSpec(api_key=os.getenv('TAVILY_API_KEY'))\n", "def search_tool(prompt:str)->list:\n", " \"return only search result from the web\"\n", " results = search.search(prompt)\n", " return [result.text for result in results]\n", "search_toolkit = FunctionTool.from_defaults(fn=search_tool)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "llm = Groq(model = \"gemma2-9b-it\")\n", "agent = ReActAgent.from_tools([search_toolkit],llm=llm,verbose=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "> Running step 72522799-577e-4630-afd1-3f7637988a23. Step input: what is the addition of 25 and 26?\n", "\u001b[1;3;38;5;200mThought: I can answer without using any more tools. I'll use the user's language to answer\n", "Answer: 51\n", "\u001b[0m" ] } ], "source": [ "response = agent.chat(\"what is the instagram link of Soumyadip Changder?\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" } }, "nbformat": 4, "nbformat_minor": 2 }