Spaces:
Running
Running
cyberosa
commited on
Commit
·
a1fd0ab
1
Parent(s):
9e71dfc
fixing the tool
Browse files- tools/calories_checker.py +12 -3
tools/calories_checker.py
CHANGED
|
@@ -18,11 +18,20 @@ class CaloriesCheckerTool(Tool):
|
|
| 18 |
def __init__(self, *args, **kwargs):
|
| 19 |
self.is_initialized = False
|
| 20 |
self.api_key = os.environ.get("CALORIES_API_KEY", None)
|
|
|
|
| 21 |
|
| 22 |
def forward(self, query: str) -> list[dict[str, Any]]:
|
| 23 |
-
api_url = "https://api.
|
| 24 |
-
response = requests.get(
|
|
|
|
|
|
|
| 25 |
if response.status_code == requests.codes.ok:
|
| 26 |
return response.text
|
| 27 |
|
| 28 |
-
return [{"Error": response.status_code, "message":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def __init__(self, *args, **kwargs):
|
| 19 |
self.is_initialized = False
|
| 20 |
self.api_key = os.environ.get("CALORIES_API_KEY", None)
|
| 21 |
+
print(self.api_key)
|
| 22 |
|
| 23 |
def forward(self, query: str) -> list[dict[str, Any]]:
|
| 24 |
+
api_url = "https://api.calorieninjas.com/v1/nutrition?query="
|
| 25 |
+
response = requests.get(
|
| 26 |
+
api_url + query, headers={"X-Api-Key": str(self.api_key)}
|
| 27 |
+
)
|
| 28 |
if response.status_code == requests.codes.ok:
|
| 29 |
return response.text
|
| 30 |
|
| 31 |
+
return [{"Error": response.status_code, "message": response.text}]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
query = "bread with fried green peppers"
|
| 36 |
+
tool = CaloriesCheckerTool()
|
| 37 |
+
print(tool.forward(query=query))
|