lautel commited on
Commit
fbbbedb
·
verified ·
1 Parent(s): 02af49f

Upload 2 files

Browse files
Files changed (2) hide show
  1. agentic/langgraph_agent.py +2 -1
  2. agentic/tools.py +36 -4
agentic/langgraph_agent.py CHANGED
@@ -40,7 +40,8 @@ class LangGraphAgent4GAIA:
40
  add_list,
41
  web_search,
42
  arxiv_search,
43
- wiki_search
 
44
  ]
45
 
46
  # 1. Build graph
 
40
  add_list,
41
  web_search,
42
  arxiv_search,
43
+ wiki_search,
44
+ read_xlsx_file
45
  ]
46
 
47
  # 1. Build graph
agentic/tools.py CHANGED
@@ -1,8 +1,11 @@
 
 
 
 
1
  from langchain_core.tools import tool
2
  from langchain_community.tools import DuckDuckGoSearchResults
3
  from langchain_community.tools.tavily_search import TavilySearchResults
4
  from langchain_community.document_loaders import ArxivLoader, WikipediaLoader
5
- from typing import List
6
 
7
  @tool
8
  def add(a: int, b: int) -> int:
@@ -78,7 +81,7 @@ def web_search(query: str) -> str:
78
  search_docs = TavilySearchResults(max_results=3).invoke({'query': query})
79
  formatted_search_docs = "\n\n---\n\n".join(
80
  [
81
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
82
  for doc in search_docs
83
  ])
84
  return f"web_results:\n{formatted_search_docs}"
@@ -93,7 +96,7 @@ def arxiv_search(query: str) -> str:
93
  search_docs = ArxivLoader(query=query, load_max_docs=3).load()
94
  formatted_search_docs = "\n\n---\n\n".join(
95
  [
96
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
97
  for doc in search_docs
98
  ])
99
  return f"arxiv_content:\n{formatted_search_docs}"
@@ -108,7 +111,36 @@ def wiki_search(query: str) -> str:
108
  search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
109
  formatted_search_docs = "\n\n---\n\n".join(
110
  [
111
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
112
  for doc in search_docs
113
  ])
114
  return f"wikipedia_content:\n{formatted_search_docs}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import pandas as pd
3
+ from io import BytesIO
4
+ from typing import List
5
  from langchain_core.tools import tool
6
  from langchain_community.tools import DuckDuckGoSearchResults
7
  from langchain_community.tools.tavily_search import TavilySearchResults
8
  from langchain_community.document_loaders import ArxivLoader, WikipediaLoader
 
9
 
10
  @tool
11
  def add(a: int, b: int) -> int:
 
81
  search_docs = TavilySearchResults(max_results=3).invoke({'query': query})
82
  formatted_search_docs = "\n\n---\n\n".join(
83
  [
84
+ f'<Document title="{doc["title"]}>"\n{doc["content"]}\n</Document>'
85
  for doc in search_docs
86
  ])
87
  return f"web_results:\n{formatted_search_docs}"
 
96
  search_docs = ArxivLoader(query=query, load_max_docs=3).load()
97
  formatted_search_docs = "\n\n---\n\n".join(
98
  [
99
+ f'<Document title="{doc.metadata["Title"]}>"\n{doc.metadata["Summary"]}\n</Document>'
100
  for doc in search_docs
101
  ])
102
  return f"arxiv_content:\n{formatted_search_docs}"
 
111
  search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
112
  formatted_search_docs = "\n\n---\n\n".join(
113
  [
114
+ f'<Document title="{doc.metadata["Title"]}>"\n{doc.metadata["Summary"]}\n</Document>'
115
  for doc in search_docs
116
  ])
117
  return f"wikipedia_content:\n{formatted_search_docs}"
118
+
119
+
120
+ @tool
121
+ def read_xlsx_file(file_location: str) -> str:
122
+ """Read an .xlsx file from a path and return its contents as a string.
123
+
124
+ Args:
125
+ file_location (str): Path to the xlsx file.
126
+ """
127
+ # Build the full file URL
128
+ base_name = file_location.split(".")[0]
129
+ file_url = f"https://agents-course-unit4-scoring.hf.space/files/{base_name}"
130
+
131
+ # Download the file
132
+ response = requests.get(file_url)
133
+ if response.status_code != 200:
134
+ raise RuntimeError(f"Failed to download file: {file_url}")
135
+
136
+ # Load the xlsx file into a pandas ExcelFile object
137
+ df_dict = pd.read_excel(BytesIO(response.content), sheet_name=None)
138
+
139
+ # Convert all sheets to a single formatted string
140
+ text_output = ""
141
+ for sheet_name, sheet_df in df_dict.items():
142
+ text_output += f"--- Sheet: {sheet_name} ---\n"
143
+ text_output += sheet_df.to_string(index=False)
144
+ text_output += "\n\n"
145
+
146
+ return f"xlsx file content:\n{text_output.strip()}"