DTStudios commited on
Commit
5401172
·
verified ·
1 Parent(s): 0f992dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -56
app.py CHANGED
@@ -1,6 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool,HfApiModel,load_tool,tool
2
- import datetime
3
- from duckduckgo_search import DDGS
4
  import requests
5
  import pytz
6
  import yaml
@@ -9,85 +8,54 @@ from tools.final_answer import FinalAnswerTool
9
 
10
 
11
  @tool
12
- def DuckDuckGoSearchTool (web_search: str) -> str:
13
- """"Performs a DuckDuckGo web search based on your query (think a Google search) then returns the top search results.Perform a DuckDuckGo search and return formatted results.
 
14
 
15
  Args:
16
- web_search (str): The query string to search for.
 
17
 
18
  Returns:
19
- str: A formatted string containing the search results.
20
  """
21
- # your implementation here
22
- ddgs = DDGS()
23
- results = DuckDuckGoSearchTool.text(web_search, max_results=10)
24
- if not results:
25
- raise Exception("No results found! Try a less restrictive/shorter query.")
26
-
27
- postprocessed_results = [
28
- f"[{r['title']}]({r['href']})\n{r['body']}" for r in results
29
- ]
30
- return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
31
 
32
- @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
34
- """A tool that fetches the current local time in a specified timezone.
 
 
35
  Args:
36
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
37
  """
38
- try:
39
- # Create timezone object
40
- tz = pytz.timezone(timezone)
41
- # Get current time in that timezone
42
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
43
- return f"The current local time in {timezone} is: {local_time}"
44
- except Exception as e:
45
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
46
 
 
 
 
47
 
48
  final_answer = FinalAnswerTool()
49
 
50
  # 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:
51
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
52
 
53
- model = HfApiModel(
54
- max_tokens=2096,
55
- temperature=0.5,
56
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
57
- custom_role_conversions=None,
58
- )
59
 
60
-
61
- # Import tool from Hub
62
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
63
-
64
- with open("prompts.yaml", 'r') as stream:
65
- prompt_templates = yaml.safe_load(stream)
66
-
67
- # Tools list (no registry object needed)
68
  tool=[
69
- DuckDuckGoSearchTool,
70
  get_current_time_in_timezone,
71
  FinalAnswerTool(),
72
- load_tool("agents-course/text-to-image", trust_remote_code=True),
73
  ]
74
 
75
- model = HfApiModel(
76
- model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
77
- max_tokens=2048,
78
- temperature=0.5
79
- )
80
- with open("prompts.yaml", "r") as stream:
81
- prompt_templates = yaml.safe_load(stream)
82
-
83
- # --- Agent setup ---
84
-
85
  agent = CodeAgent(
86
- tools=tool,
87
  model= model,
88
  add_base_tools=True,
89
- name="MyAgent",
90
- description="Agent with web search and time lookup tools"
91
  )
92
 
93
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool,HfApiModel,load_tool,tool
2
+ import datetime
 
3
  import requests
4
  import pytz
5
  import yaml
 
8
 
9
 
10
  @tool
11
+ def add_numbers(a: int, b: int) -> int:
12
+ """
13
+ Add two numbers together.
14
 
15
  Args:
16
+ a (int): The first number.
17
+ b (int): The second number.
18
 
19
  Returns:
20
+ int: The sum of the two numbers.
21
  """
22
+ return a + b
 
 
 
 
 
 
 
 
 
23
 
24
+ @tool
25
  def get_current_time_in_timezone(timezone: str) -> str:
26
+ """
27
+ Get the current time in a given timezone.
28
+
29
  Args:
30
+ timezone (str): A valid timezone string (e.g., 'America/New_York').
31
+
32
+ Returns:
33
+ str: The current time in that timezone, formatted as a string.
34
  """
35
+ from datetime import datetime
36
+ import pytz
 
 
 
 
 
 
37
 
38
+ tz = pytz.timezone(timezone)
39
+ now = datetime.now(tz)
40
+ return now.strftime("%Y-%m-%d %H:%M:%S %Z")
41
 
42
  final_answer = FinalAnswerTool()
43
 
44
  # 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:
45
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
46
 
47
+ model = HfApiModel(model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded)
 
 
 
 
 
48
 
 
 
 
 
 
 
 
 
49
  tool=[
50
+ add_numbers,
51
  get_current_time_in_timezone,
52
  FinalAnswerTool(),
 
53
  ]
54
 
 
 
 
 
 
 
 
 
 
 
55
  agent = CodeAgent(
56
+ tool=tool
57
  model= model,
58
  add_base_tools=True,
 
 
59
  )
60
 
61