satishpaib commited on
Commit
985d942
·
verified ·
1 Parent(s): dc1f8e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -19
app.py CHANGED
@@ -2,56 +2,77 @@ from smolagents import (
2
  CodeAgent,
3
  DuckDuckGoSearchTool,
4
  FinalAnswerTool,
 
5
  load_tool,
6
  tool,
7
  GradioUI
8
  )
9
 
10
- from smolagents.models import InferenceClientModel
11
  import datetime
12
- import requests
13
  import pytz
14
  import yaml
15
 
 
16
  @tool
17
- def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
18
- # Keep this format for the tool description / args description but feel free to modify the tool
19
- """A tool that does nothing yet
20
  Args:
21
  arg1: the first argument
22
  arg2: the second argument
23
  """
24
- return "What magic will you build ?"
 
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.
 
29
  Args:
30
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
31
  """
32
  try:
33
- # Create timezone object
34
  tz = pytz.timezone(timezone)
35
- # Get current time in that timezone
36
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
37
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
 
38
  except Exception as e:
39
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
40
 
41
  final_answer = FinalAnswerTool()
42
- model = InferenceClientModel(
 
 
 
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
46
- custom_role_conversions=None,
47
  )
48
 
49
- with open("prompts.yaml", 'r') as stream:
 
50
  prompt_templates = yaml.safe_load(stream)
51
- # We're creating our CodeAgent
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer, get_current_time_in_timezone], # add your tools here (don't remove final_answer)
 
 
 
 
 
 
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
@@ -61,4 +82,5 @@ agent = CodeAgent(
61
  prompt_templates=prompt_templates
62
  )
63
 
 
64
  GradioUI(agent).launch()
 
2
  CodeAgent,
3
  DuckDuckGoSearchTool,
4
  FinalAnswerTool,
5
+ HfApiModel,
6
  load_tool,
7
  tool,
8
  GradioUI
9
  )
10
 
 
11
  import datetime
 
12
  import pytz
13
  import yaml
14
 
15
+
16
  @tool
17
+ def my_custom_tool(arg1: str, arg2: int) -> str:
18
+ """A tool that does nothing yet
19
+
20
  Args:
21
  arg1: the first argument
22
  arg2: the second argument
23
  """
24
+ return "What magic will you build?"
25
+
26
 
27
  @tool
28
  def get_current_time_in_timezone(timezone: str) -> str:
29
+ """Fetch the current local time in a specified timezone.
30
+
31
  Args:
32
+ timezone: A valid timezone string like 'Asia/Kolkata'
33
  """
34
  try:
 
35
  tz = pytz.timezone(timezone)
36
+
37
+ local_time = datetime.datetime.now(tz).strftime(
38
+ "%Y-%m-%d %H:%M:%S"
39
+ )
40
+
41
+ return (
42
+ f"The current local time in "
43
+ f"{timezone} is: {local_time}"
44
+ )
45
+
46
  except Exception as e:
47
+ return (
48
+ f"Error fetching time for timezone "
49
+ f"'{timezone}': {str(e)}"
50
+ )
51
+
52
 
53
  final_answer = FinalAnswerTool()
54
+
55
+
56
+ model = HfApiModel(
57
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
58
  max_tokens=2096,
59
  temperature=0.5,
 
 
60
  )
61
 
62
+
63
+ with open("prompts.yaml", "r") as stream:
64
  prompt_templates = yaml.safe_load(stream)
65
+
66
+
67
  agent = CodeAgent(
68
  model=model,
69
+
70
+ tools=[
71
+ get_current_time_in_timezone,
72
+ my_custom_tool,
73
+ final_answer
74
+ ],
75
+
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,
 
82
  prompt_templates=prompt_templates
83
  )
84
 
85
+
86
  GradioUI(agent).launch()