tu101 commited on
Commit
42c4e9d
·
verified ·
1 Parent(s): d8efcec

updatetool

Browse files
Files changed (1) hide show
  1. tools.py +55 -0
tools.py CHANGED
@@ -17,6 +17,61 @@ from huggingface_hub import list_models
17
  from pathlib import Path
18
  import json
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  def extract_image_text(img_path: str) -> str:
22
  """
 
17
  from pathlib import Path
18
  import json
19
 
20
+ def wiki_search(query: str) -> str:
21
+ """Search Wikipedia for a query and return maximum 2 results.
22
+
23
+ Args:
24
+ query: The search query."""
25
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
26
+ formatted_search_docs = "\n\n---\n\n".join(
27
+ [
28
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
29
+ for doc in search_docs
30
+ ])
31
+ return {"wiki_results": formatted_search_docs}
32
+
33
+ wiki_search_tool = Tool(
34
+ name="wiki_search",
35
+ func=wiki_search,
36
+ description="Searches for and retrieves information on Wikipedia using an inputted query."
37
+ )
38
+
39
+ def web_search(query: str) -> str:
40
+ """Search Tavily for a query and return maximum 3 results.
41
+
42
+ Args:
43
+ query: The search query."""
44
+ search_docs = TavilySearchResults(max_results=3).invoke(query=query)
45
+ formatted_search_docs = "\n\n---\n\n".join(
46
+ [
47
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
48
+ for doc in search_docs
49
+ ])
50
+ return {"web_results": formatted_search_docs}
51
+ web_search_tool = Tool(
52
+ name="web_search",
53
+ func=web_search,
54
+ description="Searches for and retrieves information online using an inputted query using Tavily."
55
+ )
56
+
57
+ def arvix_search(query: str) -> str:
58
+ """Search Arxiv for a query and return maximum 3 result.
59
+
60
+ Args:
61
+ query: The search query."""
62
+ search_docs = ArxivLoader(query=query, load_max_docs=3).load()
63
+ formatted_search_docs = "\n\n---\n\n".join(
64
+ [
65
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
66
+ for doc in search_docs
67
+ ])
68
+ return {"arvix_results": formatted_search_docs}
69
+
70
+ arvix_search_tool = Tool(
71
+ name="arvix_search",
72
+ func=arvix_search,
73
+ description="Searches for and retrieves information online using an inputted query on the website arvix, that is a database storing many factual scientific papers."
74
+ )
75
 
76
  def extract_image_text(img_path: str) -> str:
77
  """