alekn commited on
Commit
e6dccaa
·
verified ·
1 Parent(s): b493391

Update tools

Browse files
Files changed (1) hide show
  1. tools +20 -1
tools CHANGED
@@ -1,6 +1,9 @@
1
  import cmath
2
  from langchain_core.tools import tool
 
3
 
 
 
4
  @tool
5
  def multiply(a: float, b: float) -> float:
6
  """
@@ -78,4 +81,20 @@ def square_root(a: float) -> float | complex:
78
  """
79
  if a >= 0:
80
  return a**0.5
81
- return cmath.sqrt(a)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import cmath
2
  from langchain_core.tools import tool
3
+ from langchain_community.document_loaders import WikipediaLoader
4
 
5
+
6
+ ## MATH TOOLS
7
  @tool
8
  def multiply(a: float, b: float) -> float:
9
  """
 
81
  """
82
  if a >= 0:
83
  return a**0.5
84
+ return cmath.sqrt(a)
85
+
86
+
87
+ ## SEARCH TOOLS
88
+ @tool
89
+ def wiki_search(query: str) -> str:
90
+ """Search Wikipedia for a query and return maximum 2 results.
91
+ Args:
92
+ query: The search query."""
93
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).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}\n</Document>'
97
+ for doc in search_docs
98
+ ]
99
+ )
100
+ return {"wiki_results": formatted_search_docs}