Spaces:
Sleeping
Sleeping
Download utils/custom_tools.py from hasmalik/logical_reasoning_agent: direct link, hf CLI and curl.
- Browser
- Download file 636 Bytes
-
https://huggingface.co/spaces/hasmalik/logical_reasoning_agent/resolve/main/utils/custom_tools.py
- Command line
-
hf download hf://spaces/hasmalik/logical_reasoning_agent/utils/custom_tools.py
-
curl -L -o custom_tools.py https://huggingface.co/spaces/hasmalik/logical_reasoning_agent/resolve/main/utils/custom_tools.py
636 Bytes
| from langchain_core.tools import tool | |
| import numexpr | |
| import math | |
| 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)" | |
| """ | |
| 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 | |
| ) | |
| ) |