Spaces:
Sleeping
Sleeping
Luigi D'Addona
commited on
Commit
·
9280a27
1
Parent(s):
56c9ce6
aggiunto web searc tool implementata tramite Tavily
Browse files- agent.py +3 -2
- requirements.txt +1 -0
- tools.py +19 -0
agent.py
CHANGED
|
@@ -13,7 +13,7 @@ from langgraph.graph import StateGraph, END
|
|
| 13 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 14 |
|
| 15 |
# Local imports
|
| 16 |
-
from tools import get_search_tool, get_wikipedia_tool, wikipedia_search, wikipedia_search_3, execute_python_code_from_file, download_taskid_file
|
| 17 |
|
| 18 |
# Nota: per i test in locale si usa il .env
|
| 19 |
# su HuggingFace invece si usano le variabili definite in Settings/"Variables and secrets"
|
|
@@ -54,7 +54,8 @@ chat = ChatGoogleGenerativeAI(
|
|
| 54 |
temperature = GEMINI_TEMPERATURE)
|
| 55 |
|
| 56 |
# Imposta i tool
|
| 57 |
-
search_tool = get_search_tool()
|
|
|
|
| 58 |
#wikipedia_tool = get_wikipedia_tool()
|
| 59 |
|
| 60 |
tools = [search_tool, wikipedia_search_3, execute_python_code_from_file, download_taskid_file]
|
|
|
|
| 13 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 14 |
|
| 15 |
# Local imports
|
| 16 |
+
from tools import get_search_tool, get_tavily_search_tool, get_wikipedia_tool, wikipedia_search, wikipedia_search_3, execute_python_code_from_file, download_taskid_file
|
| 17 |
|
| 18 |
# Nota: per i test in locale si usa il .env
|
| 19 |
# su HuggingFace invece si usano le variabili definite in Settings/"Variables and secrets"
|
|
|
|
| 54 |
temperature = GEMINI_TEMPERATURE)
|
| 55 |
|
| 56 |
# Imposta i tool
|
| 57 |
+
#search_tool = get_search_tool()
|
| 58 |
+
search_tool = get_tavily_search_tool()
|
| 59 |
#wikipedia_tool = get_wikipedia_tool()
|
| 60 |
|
| 61 |
tools = [search_tool, wikipedia_search_3, execute_python_code_from_file, download_taskid_file]
|
requirements.txt
CHANGED
|
@@ -10,5 +10,6 @@ langchain-community
|
|
| 10 |
langchain-openai
|
| 11 |
langchain-huggingface
|
| 12 |
langchain-google-genai
|
|
|
|
| 13 |
|
| 14 |
wikipedia
|
|
|
|
| 10 |
langchain-openai
|
| 11 |
langchain-huggingface
|
| 12 |
langchain-google-genai
|
| 13 |
+
langchain-tavily
|
| 14 |
|
| 15 |
wikipedia
|
tools.py
CHANGED
|
@@ -7,6 +7,7 @@ from langchain_community.utilities import WikipediaAPIWrapper
|
|
| 7 |
from langchain_community.tools import WikipediaQueryRun
|
| 8 |
from langchain_community.document_loaders import WikipediaLoader
|
| 9 |
import wikipedia
|
|
|
|
| 10 |
from langchain_core.tools import tool
|
| 11 |
from langchain.tools import Tool
|
| 12 |
|
|
@@ -28,6 +29,24 @@ def get_search_tool():
|
|
| 28 |
return search_tool
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Wikipedia tool 1: usa WikipediaQueryRun dal package 'langchain_community.tools'
|
| 32 |
# problema: sembra ottenere solo i summary
|
| 33 |
def get_wikipedia_tool():
|
|
|
|
| 7 |
from langchain_community.tools import WikipediaQueryRun
|
| 8 |
from langchain_community.document_loaders import WikipediaLoader
|
| 9 |
import wikipedia
|
| 10 |
+
from langchain_tavily import TavilySearch
|
| 11 |
from langchain_core.tools import tool
|
| 12 |
from langchain.tools import Tool
|
| 13 |
|
|
|
|
| 29 |
return search_tool
|
| 30 |
|
| 31 |
|
| 32 |
+
def get_tavily_search_tool():
|
| 33 |
+
|
| 34 |
+
tavily_search_tool = TavilySearch(
|
| 35 |
+
max_results=5,
|
| 36 |
+
topic="general",
|
| 37 |
+
# include_answer=False,
|
| 38 |
+
# include_raw_content=False,
|
| 39 |
+
# include_images=False,
|
| 40 |
+
# include_image_descriptions=False,
|
| 41 |
+
# search_depth="basic",
|
| 42 |
+
# time_range="day",
|
| 43 |
+
# include_domains=None,
|
| 44 |
+
# exclude_domains=None
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
return tavily_search_tool
|
| 48 |
+
|
| 49 |
+
|
| 50 |
# Wikipedia tool 1: usa WikipediaQueryRun dal package 'langchain_community.tools'
|
| 51 |
# problema: sembra ottenere solo i summary
|
| 52 |
def get_wikipedia_tool():
|