IamRulo commited on
Commit
bd5ced9
·
verified ·
1 Parent(s): 100d5da

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +13 -2
agent.py CHANGED
@@ -13,6 +13,8 @@ from langchain_core.messages import SystemMessage, HumanMessage
13
  from langchain_core.tools import tool
14
  from langchain.tools.retriever import create_retriever_tool
15
 
 
 
16
  load_dotenv()
17
 
18
  @tool
@@ -105,19 +107,28 @@ def wiki_search(query: str) -> str:
105
 
106
  @tool
107
  def web_search(query: str) -> str:
108
- """Search Tavily for a query and return maximum 3 results.
109
 
110
  Args:
111
  query: The search query."""
112
 
 
113
  search_docs = TavilySearchResults(max_results=3).invoke(query=query)
114
  formatted_search_docs = "\n\n---\n\n".join(
115
  [
116
  f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
117
  for doc in search_docs
118
  ])
119
- return {"web_results": formatted_search_docs}
 
 
 
 
 
 
120
 
 
 
121
 
122
  # load the system prompt from the file
123
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
 
13
  from langchain_core.tools import tool
14
  from langchain.tools.retriever import create_retriever_tool
15
 
16
+ from duckduckgo_search import ddg
17
+
18
  load_dotenv()
19
 
20
  @tool
 
107
 
108
  @tool
109
  def web_search(query: str) -> str:
110
+ """Search Tavily/DuckDuckGo for a query and return maximum 3 results.
111
 
112
  Args:
113
  query: The search query."""
114
 
115
+ """
116
  search_docs = TavilySearchResults(max_results=3).invoke(query=query)
117
  formatted_search_docs = "\n\n---\n\n".join(
118
  [
119
  f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
120
  for doc in search_docs
121
  ])
122
+ """
123
+ search_docs = ddg(query, max_results=3)
124
+ formatted_search_docs = "\n\n---\n\n".join(
125
+ [
126
+ f'<Document source="{doc["href"]}" page=""/>\n{doc["body"]}\n</Document>'
127
+ for doc in search_docs
128
+ ])
129
 
130
+
131
+ return {"web_results": formatted_search_docs}
132
 
133
  # load the system prompt from the file
134
  with open("system_prompt.txt", "r", encoding="utf-8") as f: