Mohammad Haghir commited on
Commit
10c7cb1
·
1 Parent(s): 7aef43e

arxiv ret

Browse files
Files changed (3) hide show
  1. agent_utils.py +20 -1
  2. app.py +2 -2
  3. requirements.txt +2 -1
agent_utils.py CHANGED
@@ -1,5 +1,5 @@
1
  from langchain_community.document_loaders import WikipediaLoader
2
-
3
 
4
  def wiki_ret(question: str) -> str:
5
  """ Retrieve docs from wikipedia """
@@ -18,3 +18,22 @@ def wiki_ret(question: str) -> str:
18
 
19
  return {"context": formatted_search_docs}
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from langchain_community.document_loaders import WikipediaLoader
2
+ import arxiv
3
 
4
  def wiki_ret(question: str) -> str:
5
  """ Retrieve docs from wikipedia """
 
18
 
19
  return {"context": formatted_search_docs}
20
 
21
+
22
+
23
+ def arxiv_ret(query: str, max_results: int = 3) -> str:
24
+ """Search arXiv for a given query and return a summary of top results."""
25
+ search = arxiv.Search(
26
+ query=query,
27
+ max_results=max_results,
28
+ sort_by=arxiv.SortCriterion.Relevance
29
+ )
30
+
31
+ results = []
32
+ for result in search.results():
33
+ summary = result.summary.replace("\n", " ")
34
+ results.append(f"Title: {result.title}\nAuthors: {', '.join(a.name for a in result.authors)}\nSummary: {summary}\nURL: {result.entry_id}\n")
35
+
36
+ if not results:
37
+ return "No relevant papers found."
38
+
39
+ return "\n\n".join(results)
app.py CHANGED
@@ -17,7 +17,7 @@ from langchain_core.messages import HumanMessage
17
  from langgraph.graph import START, END, StateGraph
18
  from langgraph.prebuilt import ToolNode, tools_condition
19
 
20
- from agent_utils import wiki_ret
21
 
22
  # (Keep Constants as is)
23
  # --- Constants ---
@@ -82,7 +82,7 @@ class BasicAgent:
82
  def create_graph(self):
83
  builder = StateGraph(GraphState)
84
  builder.add_node("agent", self.agent)
85
- builder.add_node("tools", ToolNode(tools = [wiki_ret]))
86
 
87
  builder.add_edge(START, "agent")
88
  builder.add_conditional_edges("agent", tools_condition)
 
17
  from langgraph.graph import START, END, StateGraph
18
  from langgraph.prebuilt import ToolNode, tools_condition
19
 
20
+ from agent_utils import wiki_ret, arxiv_ret
21
 
22
  # (Keep Constants as is)
23
  # --- Constants ---
 
82
  def create_graph(self):
83
  builder = StateGraph(GraphState)
84
  builder.add_node("agent", self.agent)
85
+ builder.add_node("tools", ToolNode(tools = [wiki_ret, arxiv_ret]))
86
 
87
  builder.add_edge(START, "agent")
88
  builder.add_conditional_edges("agent", tools_condition)
requirements.txt CHANGED
@@ -4,4 +4,5 @@ langchain-groq
4
  langchain-community
5
  langchain-core
6
  wikipedia
7
- langgraph
 
 
4
  langchain-community
5
  langchain-core
6
  wikipedia
7
+ langgraph
8
+ arxiv