File size: 2,969 Bytes
2ac4ccc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
{
"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
}
|