Spaces:
Running
Running
Support load_tool
Browse files- requirements.txt +1 -0
- wolfram-alpha-tool +0 -35
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
transformers
|
|
|
|
|
|
| 1 |
transformers
|
| 2 |
+
requests
|
wolfram-alpha-tool
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
class WolframAlpha(Tool):
|
| 2 |
-
name = "wolfram_alpha"
|
| 3 |
-
description = ("This is a tool that uses WolframAlpha to compute any mathematical question. It takes one input query, and returns a verbose result in xml format, which includes the solution.")
|
| 4 |
-
|
| 5 |
-
inputs = ["query"]
|
| 6 |
-
outputs = ["result"]
|
| 7 |
-
|
| 8 |
-
def __call__(self, query, output='xml', pod_format='plaintext'):
|
| 9 |
-
base_url = 'http://api.wolframalpha.com/v2/query'
|
| 10 |
-
|
| 11 |
-
output_opts = ['xml','json']
|
| 12 |
-
format_opts = ['plaintext', 'image', 'image,imagemap', 'mathml', 'sound', 'wav']
|
| 13 |
-
|
| 14 |
-
if output not in output_opts:
|
| 15 |
-
return f"{output} is not a correct output parameter! It must be one of these: {output_opts}"
|
| 16 |
-
|
| 17 |
-
if pod_format not in format_opts:
|
| 18 |
-
return f"{pod_format} is not a correct pod_format parameter! It must be one of these: {format_opts}"
|
| 19 |
-
|
| 20 |
-
params = {
|
| 21 |
-
'input': query,
|
| 22 |
-
'output': output,
|
| 23 |
-
'appid': CFG_appid,
|
| 24 |
-
}
|
| 25 |
-
print("About to response")
|
| 26 |
-
response = requests.get(base_url, params=params)
|
| 27 |
-
print("response:",response)
|
| 28 |
-
if response.status_code == 200:
|
| 29 |
-
if output == 'xml':
|
| 30 |
-
return response.text
|
| 31 |
-
elif output == 'json':
|
| 32 |
-
# Remove unnecessary empty spaces
|
| 33 |
-
return str(response.json())
|
| 34 |
-
else:
|
| 35 |
-
return f"There was an error with the request, with response: {response}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|