MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / build_tool

Function build_tool

bmtools/tools/arxiv/api.py:6–53  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

4
5
6def build_tool(config) -> Tool:
7 tool = Tool(
8 "Arxiv",
9 "Look up for information from scientific articles on arxiv.org",
10 name_for_model="Arxiv",
11 description_for_model=(
12 "Search information from Arxiv.org "
13 "Useful for when you need to answer questions about Physics, Mathematics, "
14 "Computer Science, Quantitative Biology, Quantitative Finance, Statistics, "
15 "Electrical Engineering, and Economics "
16 "from scientific articles on arxiv.org. "
17 "Input should be a search query."
18 ),
19 logo_url="https://your-app-url.com/.well-known/logo.png",
20 contact_email="hello@contact.com",
21 legal_info_url="hello@legal.com"
22 )
23
24 arxiv_exceptions: Any # :meta private:
25 top_k_results: int = 3
26 ARXIV_MAX_QUERY_LENGTH = 300
27 doc_content_chars_max: int = 4000
28
29 @tool.get("/get_arxiv_article_information")
30 def get_arxiv_article_information(query : str):
31 '''Run Arxiv search and get the article meta information.
32 '''
33 param = {
34 "q": query
35 }
36 try:
37 results = arxiv.Search( # type: ignore
38 query[: ARXIV_MAX_QUERY_LENGTH], max_results = top_k_results
39 ).results()
40 except arxiv_exceptions as ex:
41 return f"Arxiv exception: {ex}"
42 docs = [
43 f"Published: {result.updated.date()}\nTitle: {result.title}\n"
44 f"Authors: {', '.join(a.name for a in result.authors)}\n"
45 f"Summary: {result.summary}"
46 for result in results
47 ]
48 if docs:
49 return "\n\n".join(docs)[: doc_content_chars_max]
50 else:
51 return "No good Arxiv Result was found"
52
53 return tool

Callers

nothing calls this directly

Calls 1

ToolClass · 0.50

Tested by

no test coverage detected