EtienneB commited on
Commit
4869536
·
1 Parent(s): 1669f2b

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +17 -0
tools.py CHANGED
@@ -3,6 +3,7 @@ import math
3
  from typing import Union
4
 
5
  import pytz
 
6
  from langchain_community.tools import DuckDuckGoSearchRun
7
  from langchain_core.tools import tool
8
 
@@ -548,3 +549,19 @@ def convert_temperature(value: Union[int, float], from_unit: str, to_unit: str)
548
  return round(result, 2)
549
  except Exception as e:
550
  return f"Error converting temperature: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from typing import Union
4
 
5
  import pytz
6
+ from langchain_community.document_loaders import WikipediaLoader
7
  from langchain_community.tools import DuckDuckGoSearchRun
8
  from langchain_core.tools import tool
9
 
 
549
  return round(result, 2)
550
  except Exception as e:
551
  return f"Error converting temperature: {str(e)}"
552
+
553
+ @tool
554
+ def wiki_search(query: str) -> str:
555
+ """
556
+ Search Wikipedia for a query and return maximum 2 results.
557
+
558
+ Args:
559
+ query: The search query.
560
+ """
561
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
562
+ formatted_search_docs = "\n\n---\n\n".join(
563
+ [
564
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
565
+ for doc in search_docs
566
+ ])
567
+ return {"wiki_results": formatted_search_docs}