Spaces:
Sleeping
Sleeping
File size: 1,981 Bytes
e4a5799 54bd833 e4a5799 f312ac3 e4a5799 54bd833 e4a5799 54bd833 e4a5799 f312ac3 54bd833 e4a5799 f312ac3 e4a5799 f312ac3 e4a5799 de51740 e4a5799 54bd833 e4a5799 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import math
import os
import numexpr
from langchain_community.document_loaders import ArxivLoader
from smolagents import (
CodeAgent,
GoogleSearchTool,
InferenceClientModel,
WikipediaSearchTool,
tool,
)
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
@tool
def calculator(expression: str) -> str:
"""Calculate expression using Python's numexpr library.
Expression should be a single line mathematical expression
that solves the problem.
Examples:
"37593 * 67" for "37593 times 67"
"37593**(1/5)" for "37593^(1/5)"
Args:
expression: the expression to be compute
"""
local_dict = {"pi": math.pi, "e": math.e}
return str(
numexpr.evaluate(
expression.strip(),
global_dict={}, # restrict access to globals
local_dict=local_dict, # add common mathematical functions
)
)
@tool
def arxiv_search_tool(query: str) -> str:
"""
Searches Arxiv and returns a summary or full text of the given topic of the 5 most likely related papers, along with the page URL.
Args:
query: the topic to be searched
"""
docs = ArxivLoader(query=query, load_max_docs=5).load()
if len(docs) > 0:
return "\n".join(
[
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
for doc in docs
]
)
return "No content found"
tools = [
calculator,
arxiv_search_tool,
GoogleSearchTool(provider="serper"),
WikipediaSearchTool(),
]
model_id = "Qwen/Qwen3-235B-A22B"
model = InferenceClientModel(
model_id=model_id, token=hf_token
) # You can choose to not pass any model_id to InferenceClientModel to use a default model
agent = CodeAgent(
model=model,
tools=tools,
add_base_tools=True,
additional_authorized_imports=["pandas", "numpy", "csv", "subprocess"],
)
|