dominik.smogor commited on
Commit
d9fe58a
·
1 Parent(s): ae7a494

Added token

Browse files
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .gradio/certificate.pem
2
+ __pycache__/Gradio_UI.cpython-312.pyc
3
+ tools/__pycache__/findtz.cpython-312.pyc
app.py CHANGED
@@ -3,10 +3,15 @@ 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
@@ -33,9 +38,11 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
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
 
@@ -43,6 +50,7 @@ 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
 
@@ -55,7 +63,7 @@ with open("prompts.yaml", 'r') as 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,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import os
7
+
8
+
9
  from tools.final_answer import FinalAnswerTool
10
+ from tools.web_search import DuckDuckGoSearchTool
11
+ from tools.visit_webpage import VisitWebpageTool
12
+ from tools.findtz import FindTimezone
13
 
14
  from Gradio_UI import GradioUI
 
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
  @tool
17
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
38
  except Exception as e:
39
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
 
41
+ print (os.environ["HF_TOKEN"])
42
  final_answer = FinalAnswerTool()
43
+ web_search = DuckDuckGoSearchTool()
44
+ visit_webpage = VisitWebpageTool()
45
+ find_timezone = FindTimezone()
46
  # 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:
47
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
48
 
 
50
  max_tokens=2096,
51
  temperature=0.5,
52
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
53
+ #model_id='meta-llama/Llama-3.2-3B-Instruct',
54
  custom_role_conversions=None,
55
  )
56
 
 
63
 
64
  agent = CodeAgent(
65
  model=model,
66
+ tools=[final_answer, get_current_time_in_timezone, web_search, visit_webpage, find_timezone], ## add your tools here (don't remove final answer)
67
  max_steps=6,
68
  verbosity_level=1,
69
  grammar=None,
tools/__pycache__/final_answer.cpython-312.pyc ADDED
Binary file (1.06 kB). View file
 
tools/__pycache__/visit_webpage.cpython-312.pyc ADDED
Binary file (2.53 kB). View file
 
tools/__pycache__/web_search.cpython-312.pyc ADDED
Binary file (2.2 kB). View file
 
tools/findtz.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+ from smolagents.tools import Tool
3
+
4
+ class FindTimezone(Tool):
5
+ name = "find_timezone"
6
+ description = "Finds apropriate time zone ID if given major city name in english"
7
+ inputs = {'city': {'type': 'string', 'description': 'English name of a major city for which time zone shall be found'}}
8
+ output_type = "string"
9
+
10
+ def forward(self, city: str) -> str:
11
+ def forward(self, city: str) -> str:
12
+ # Import zoneinfo for timezone handling
13
+ from zoneinfo import available_timezones
14
+
15
+ # Get all available timezones
16
+ all_zones = available_timezones()
17
+
18
+ # Convert city to lowercase for case-insensitive matching
19
+ city = city.lower()
20
+
21
+ # Search for timezone containing the city name
22
+ for zone in all_zones:
23
+ # Split timezone into components and check if city matches
24
+ components = zone.split('/')
25
+ if len(components) > 1 and components[-1].lower().replace('_',' ') == city:
26
+ return zone
27
+
28
+ # Return None if no match found
29
+ return None
30
+ def __init__(self, *args, **kwargs):
31
+ self.is_initialized = False