Spaces:
Sleeping
Sleeping
Nguyen Nhu Trung
commited on
Commit
·
91764cb
1
Parent(s):
528d7ce
update tavily
Browse files
agent.py
CHANGED
|
@@ -12,7 +12,11 @@ from langchain_core.messages import SystemMessage, HumanMessage
|
|
| 12 |
from langchain_core.tools import tool
|
| 13 |
from langchain_core.output_parsers import StrOutputParser
|
| 14 |
from langchain_core.tools import Tool
|
| 15 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
from langchain_experimental.utilities import PythonREPL
|
| 17 |
import assemblyai as aai
|
| 18 |
|
|
@@ -26,6 +30,16 @@ repl_tool = Tool(
|
|
| 26 |
func=PythonREPL().run,
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@tool
|
| 30 |
def read_excel_file(excel_file_path: str) -> str:
|
| 31 |
"""Read the content of excel file.
|
|
@@ -80,25 +94,18 @@ def wiki_search(query: str) -> str:
|
|
| 80 |
|
| 81 |
# @tool
|
| 82 |
# def web_search(query: str) -> str:
|
| 83 |
-
# """Search
|
| 84 |
|
| 85 |
# Args:
|
| 86 |
# query: The search query."""
|
| 87 |
-
# search_docs =
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
search_docs = TavilySearchResults(max_results=3).invoke(query=query)
|
| 96 |
-
formatted_search_docs = "\n\n---\n\n".join(
|
| 97 |
-
[
|
| 98 |
-
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 99 |
-
for doc in search_docs
|
| 100 |
-
])
|
| 101 |
-
return {"web_results": formatted_search_docs}
|
| 102 |
|
| 103 |
|
| 104 |
system_prompt = """
|
|
@@ -113,7 +120,8 @@ sys_msg = SystemMessage(content=system_prompt)
|
|
| 113 |
|
| 114 |
tools = [
|
| 115 |
wiki_search,
|
| 116 |
-
|
|
|
|
| 117 |
repl_tool,
|
| 118 |
read_excel_file,
|
| 119 |
transcribe_audio
|
|
|
|
| 12 |
from langchain_core.tools import tool
|
| 13 |
from langchain_core.output_parsers import StrOutputParser
|
| 14 |
from langchain_core.tools import Tool
|
| 15 |
+
from langchain_tavily import TavilySearch
|
| 16 |
+
from langchain_tavily import TavilySearch, TavilyExtract
|
| 17 |
+
|
| 18 |
+
# from langchain_community.tools.tavily_search import TavilySearchResults
|
| 19 |
+
|
| 20 |
from langchain_experimental.utilities import PythonREPL
|
| 21 |
import assemblyai as aai
|
| 22 |
|
|
|
|
| 30 |
func=PythonREPL().run,
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Initialize Tavily Search Tool
|
| 34 |
+
tavily_search_tool = TavilySearch(
|
| 35 |
+
max_results=5,
|
| 36 |
+
topic="general",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Initialize Tavily Extract Tool
|
| 40 |
+
tavily_extract_tool = TavilyExtract()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
@tool
|
| 44 |
def read_excel_file(excel_file_path: str) -> str:
|
| 45 |
"""Read the content of excel file.
|
|
|
|
| 94 |
|
| 95 |
# @tool
|
| 96 |
# def web_search(query: str) -> str:
|
| 97 |
+
# """Search Tavily for a query and return maximum 3 results.
|
| 98 |
|
| 99 |
# Args:
|
| 100 |
# query: The search query."""
|
| 101 |
+
# search_docs = TavilySearchResults(max_results=5).invoke(query=query)
|
| 102 |
+
# formatted_search_docs = "\n\n---\n\n".join(
|
| 103 |
+
# [
|
| 104 |
+
# f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 105 |
+
# for doc in search_docs
|
| 106 |
+
# ])
|
| 107 |
+
# print({"web_results": formatted_search_docs})
|
| 108 |
+
# return {"web_results": formatted_search_docs}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
system_prompt = """
|
|
|
|
| 120 |
|
| 121 |
tools = [
|
| 122 |
wiki_search,
|
| 123 |
+
tavily_search_tool,
|
| 124 |
+
tavily_extract_tool,
|
| 125 |
repl_tool,
|
| 126 |
read_excel_file,
|
| 127 |
transcribe_audio
|