tu101 commited on
Commit
220f625
·
verified ·
1 Parent(s): 0c4fa00
Files changed (1) hide show
  1. tools.py +18 -8
tools.py CHANGED
@@ -282,27 +282,37 @@ wiki_search_tool = Tool(
282
 
283
  def web_search(query: str) -> str:
284
  """Search Tavily for a query and return maximum 5 results. Make sure to format the args as query and have the query sound like a sentence, hopefully matching part of the question the search is used for.
285
-
286
  Args:
287
- query: The search query. The query fulfils the argument that is input."""
288
  tavily = TavilySearch(max_results=5, topic="general", include_answer=True, include_image_descriptions=True)
289
  raw_results = tavily.invoke(query)
290
-
 
 
 
 
291
  docs = []
292
- for idx, text in enumerate(raw_results):
 
 
 
 
 
293
  docs.append(Document(
294
- page_content=text,
295
- metadata={"source": f"Tavily result #{idx+1}"}
296
  ))
297
-
298
  formatted_docs = "\n\n---\n\n".join(
299
  f'<Document source="{doc.metadata["source"]}">\n'
300
  f'{doc.page_content}\n'
301
  f'</Document>'
302
  for doc in docs
303
  )
304
- return {"web_results": formatted_docs}
305
 
 
 
 
306
  web_search_tool = Tool(
307
  name="web_search",
308
  func=web_search,
 
282
 
283
  def web_search(query: str) -> str:
284
  """Search Tavily for a query and return maximum 5 results. Make sure to format the args as query and have the query sound like a sentence, hopefully matching part of the question the search is used for.
 
285
  Args:
286
+ query: The search query. The query fulfils the argument that is input."""
287
  tavily = TavilySearch(max_results=5, topic="general", include_answer=True, include_image_descriptions=True)
288
  raw_results = tavily.invoke(query)
289
+
290
+ # Extract the actual search results from the response dictionary
291
+ # The 'results' key contains the list of search results we want
292
+ search_results = raw_results.get('results', [])
293
+
294
  docs = []
295
+ for idx, result in enumerate(search_results):
296
+ # Each result is a dictionary with keys like 'title', 'content', 'url'
297
+ # We'll use the content as the main text and include other metadata
298
+ content = result.get('content', result.get('title', 'No content available'))
299
+ source_url = result.get('url', f'Tavily result #{idx+1}')
300
+
301
  docs.append(Document(
302
+ page_content=content,
303
+ metadata={"source": source_url, "title": result.get('title', 'No title')}
304
  ))
305
+
306
  formatted_docs = "\n\n---\n\n".join(
307
  f'<Document source="{doc.metadata["source"]}">\n'
308
  f'{doc.page_content}\n'
309
  f'</Document>'
310
  for doc in docs
311
  )
 
312
 
313
+ # Fix the return type - should return string, not dictionary
314
+ return formatted_docs
315
+
316
  web_search_tool = Tool(
317
  name="web_search",
318
  func=web_search,