Israelbliz commited on
Commit
44be4ee
·
verified ·
1 Parent(s): 67551e9

The agent didno

Browse files
Files changed (1) hide show
  1. app.py +9 -74
app.py CHANGED
@@ -1,85 +1,20 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
- import datetime
3
- import pytz
4
- import yaml
5
- from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
8
- # -------------------- TOOLS --------------------
9
-
10
- @tool
11
- def get_place_info_from_timezone(timezone: str) -> str:
12
- """Get basic information about a place using its timezone.
13
-
14
- Args:
15
- timezone: A valid timezone string (e.g., 'Africa/Lagos', 'Europe/London')
16
- """
17
- try:
18
- tz = pytz.timezone(timezone)
19
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
20
-
21
- parts = timezone.split("/")
22
- region = parts[0]
23
- city = parts[1] if len(parts) > 1 else "Unknown"
24
-
25
- return (
26
- f"Timezone: {timezone}\n"
27
- f"Region: {region}\n"
28
- f"City/Area: {city.replace('_', ' ')}\n"
29
- f"Current local time: {local_time}"
30
- )
31
-
32
- except Exception as e:
33
- return f"Error: Could not retrieve information for '{timezone}'. {str(e)}"
34
-
35
-
36
  @tool
37
- def get_current_time_in_timezone(timezone: str) -> str:
38
- """Fetch the current local time in a specified timezone.
39
-
40
- Args:
41
- timezone: A valid timezone string (e.g., 'America/New_York')
42
- """
43
- try:
44
- tz = pytz.timezone(timezone)
45
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
46
- return f"The current local time in {timezone} is: {local_time}"
47
- except Exception as e:
48
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
49
-
50
-
51
- # -------------------- FINAL ANSWER TOOL --------------------
52
-
53
- final_answer = FinalAnswerTool()
54
-
55
- # -------------------- MODEL --------------------
56
 
57
  model = HfApiModel(
58
- max_tokens=2096,
59
- temperature=0.5,
60
- model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
61
- custom_role_conversions=None,
62
  )
63
 
64
- # -------------------- PROMPTS --------------------
65
-
66
- with open("prompts.yaml", "r") as stream:
67
- prompt_templates = yaml.safe_load(stream)
68
-
69
- # -------------------- AGENT --------------------
70
-
71
  agent = CodeAgent(
72
  model=model,
73
- tools=[
74
- get_place_info_from_timezone,
75
- get_current_time_in_timezone,
76
- final_answer, # DO NOT REMOVE
77
- ],
78
- max_steps=6,
79
- verbosity_level=1,
80
- prompt_templates=prompt_templates,
81
  )
82
 
83
- # -------------------- UI --------------------
84
-
85
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, HfApiModel, tool
 
 
 
 
2
  from Gradio_UI import GradioUI
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  @tool
5
+ def ping() -> str:
6
+ """Simple test tool"""
7
+ return "pong"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  model = HfApiModel(
10
+ model_id="mistralai/Mistral-7B-Instruct-v0.2",
11
+ max_tokens=512,
 
 
12
  )
13
 
 
 
 
 
 
 
 
14
  agent = CodeAgent(
15
  model=model,
16
+ tools=[ping],
17
+ max_steps=3,
 
 
 
 
 
 
18
  )
19
 
20
+ GradioUI(agent).launch()