Spaces:
Sleeping
Sleeping
cyberosa
commited on
Commit
·
b3409ed
1
Parent(s):
5dad656
fixing type annotations
Browse files
tools/calories_checker.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import requests
|
2 |
import os
|
3 |
-
from typing import Any, Optional,
|
4 |
from smolagents.tools import Tool
|
5 |
|
6 |
|
7 |
class CaloriesCheckerTool(Tool):
|
8 |
name = "calories_check"
|
9 |
-
description = "Based on a query including some food you want to
|
10 |
inputs = {
|
11 |
"query": {
|
12 |
"type": "string",
|
@@ -19,7 +19,7 @@ class CaloriesCheckerTool(Tool):
|
|
19 |
self.is_initialized = False
|
20 |
self.api_key = os.environ.get("CALORIES_API_KEY", None)
|
21 |
|
22 |
-
def forward(self, query: str) ->
|
23 |
api_url = "https://api.api-ninjas.com/v1/nutrition?query={}".format(query)
|
24 |
response = requests.get(api_url, headers={"X-Api-Key": self.api_key})
|
25 |
if response.status_code == requests.codes.ok:
|
|
|
1 |
import requests
|
2 |
import os
|
3 |
+
from typing import Any, Optional, List, dict
|
4 |
from smolagents.tools import Tool
|
5 |
|
6 |
|
7 |
class CaloriesCheckerTool(Tool):
|
8 |
name = "calories_check"
|
9 |
+
description = "Based on a query including some food you want to check, it returns the calories and other nutritional parameters of the food"
|
10 |
inputs = {
|
11 |
"query": {
|
12 |
"type": "string",
|
|
|
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]:
|
23 |
api_url = "https://api.api-ninjas.com/v1/nutrition?query={}".format(query)
|
24 |
response = requests.get(api_url, headers={"X-Api-Key": self.api_key})
|
25 |
if response.status_code == requests.codes.ok:
|