cyberosa commited on
Commit
6155246
·
1 Parent(s): ae7a494

adding calories checker tool

Browse files
Files changed (4) hide show
  1. README.md +4 -4
  2. agent.json +1 -1
  3. app.py +23 -14
  4. tools/calories_checker.py +28 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: First Agent Template
3
- emoji:
4
- colorFrom: pink
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.15.0
8
  app_file: app.py
 
1
  ---
2
+ title: Nutritionist Agent Assistant
3
+ emoji: 🥦
4
+ colorFrom: green
5
+ colorTo: white
6
  sdk: gradio
7
  sdk_version: 5.15.0
8
  app_file: app.py
agent.json CHANGED
@@ -8,7 +8,7 @@
8
  "class": "HfApiModel",
9
  "data": {
10
  "max_tokens": 2096,
11
- "temperature": 0.5,
12
  "last_input_token_count": null,
13
  "last_output_token_count": null,
14
  "model_id": "Qwen/Qwen2.5-Coder-32B-Instruct",
 
8
  "class": "HfApiModel",
9
  "data": {
10
  "max_tokens": 2096,
11
+ "temperature": 0.3,
12
  "last_input_token_count": null,
13
  "last_output_token_count": null,
14
  "model_id": "Qwen/Qwen2.5-Coder-32B-Instruct",
app.py CHANGED
@@ -1,23 +1,28 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
15
  Args:
16
  arg1: the first argument
17
  arg2: the second argument
18
  """
19
  return "What magic will you build ?"
20
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -35,35 +40,39 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
40
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
41
 
42
  model = HfApiModel(
43
- max_tokens=2096,
44
- temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
- custom_role_conversions=None,
47
  )
48
 
49
 
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
53
- with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
-
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
62
  planning_interval=None,
63
  name=None,
64
  description=None,
65
- prompt_templates=prompt_templates
66
  )
67
 
68
 
69
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from tools.calories_checker import CaloriesCheckerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def my_custom_tool(
15
+ arg1: str, arg2: int
16
+ ) -> str: # it's import to specify the return type
17
+ # Keep this format for the description / args / args description but feel free to modify the tool
18
+ """A tool that does nothing yet
19
  Args:
20
  arg1: the first argument
21
  arg2: the second argument
22
  """
23
  return "What magic will you build ?"
24
 
25
+
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
28
  """A tool that fetches the current local time in a specified timezone.
 
40
 
41
 
42
  final_answer = FinalAnswerTool()
43
+ calories_checker = CaloriesCheckerTool()
44
 
45
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
46
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
47
 
48
  model = HfApiModel(
49
+ max_tokens=2096,
50
+ temperature=0.5,
51
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # it is possible that this model may be overloaded
52
+ custom_role_conversions=None,
53
  )
54
 
55
 
56
  # Import tool from Hub
57
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
58
 
59
+ with open("prompts.yaml", "r") as stream:
60
  prompt_templates = yaml.safe_load(stream)
61
+
62
  agent = CodeAgent(
63
  model=model,
64
+ tools=[
65
+ final_answer,
66
+ calories_checker,
67
+ ], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,
71
  planning_interval=None,
72
  name=None,
73
  description=None,
74
+ prompt_templates=prompt_templates,
75
  )
76
 
77
 
78
+ GradioUI(agent).launch()
tools/calories_checker.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from typing import Any, Optional, list
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 eat, it returns the calories and other nutritional parameters of the food"
10
+ inputs = {
11
+ "query": {
12
+ "type": "string",
13
+ "description": "The query with the food you want to check.",
14
+ }
15
+ }
16
+ output_type = "list"
17
+
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:
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:
26
+ return response.text
27
+
28
+ return [{"Error": response.status_code, "message": "response.text"}]