phanerozoic commited on
Commit
6abe198
·
verified ·
1 Parent(s): 559cf33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -11,21 +11,21 @@ from tools.web_search import DuckDuckGoSearchTool
11
 
12
  from Gradio_UI import GradioUI
13
 
14
- # Example tool: a custom tool that currently does nothing—feel free to enhance it!
15
  @tool
16
  def my_custom_tool(arg1: str, arg2: int) -> str:
17
- """A tool that does nothing yet.
18
 
19
  Args:
20
- arg1: the first argument.
21
- arg2: the second argument.
22
  """
23
  return "What magic will you build ?"
24
 
25
- # Example tool: get current time in a specified timezone
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
 
30
  Args:
31
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
@@ -37,21 +37,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
37
  except Exception as e:
38
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
 
40
- # Instantiate the FinalAnswerTool (required)
41
  final_answer = FinalAnswerTool()
42
 
43
- # Import an image generation tool from the Hub (if desired)
44
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
45
-
46
- # Instantiate local tools for web search and webpage visits
47
  search_tool = DuckDuckGoSearchTool() # Defined in tools/web_search.py
 
 
48
  visit_tool = VisitWebpageTool() # Defined in tools/visit_webpage.py
49
 
50
  # Define the model configuration using HfApiModel
51
  model = HfApiModel(
52
  max_tokens=2096,
53
  temperature=0.5,
54
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # You can change this if the model is overloaded.
55
  custom_role_conversions=None,
56
  )
57
 
@@ -59,16 +59,15 @@ model = HfApiModel(
59
  with open("prompts.yaml", 'r') as stream:
60
  prompt_templates = yaml.safe_load(stream)
61
 
62
- # Create the CodeAgent, including all the tools we want to enable:
63
  agent = CodeAgent(
64
  model=model,
65
  tools=[
66
  final_answer, # Must remain included.
67
  search_tool, # Enables web search.
68
  visit_tool, # Enables webpage visits.
69
- my_custom_tool, # Your custom tool (modify as desired).
70
- get_current_time_in_timezone,
71
- image_generation_tool # Enables image generation via a Hub tool.
72
  ],
73
  max_steps=6,
74
  verbosity_level=1,
 
11
 
12
  from Gradio_UI import GradioUI
13
 
14
+ # Example Tool (non-functioning): provided purely as a template.
15
  @tool
16
  def my_custom_tool(arg1: str, arg2: int) -> str:
17
+ """Example Tool: A non-functional tool provided as a template.
18
 
19
  Args:
20
+ arg1: The first argument.
21
+ arg2: The second argument.
22
  """
23
  return "What magic will you build ?"
24
 
25
+ # Working Tool: Fetches the current local time in a specified timezone.
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
28
+ """Working Tool: Fetches the current local time in a specified timezone.
29
 
30
  Args:
31
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
37
  except Exception as e:
38
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
 
40
+ # Instantiate the FinalAnswerTool (required for returning final answers)
41
  final_answer = FinalAnswerTool()
42
 
43
+ # Instantiate working local tools:
44
+ # Web Search Tool: Uses DuckDuckGo to perform a web search.
 
 
45
  search_tool = DuckDuckGoSearchTool() # Defined in tools/web_search.py
46
+
47
+ # Webpage Visit Tool: Visits a URL and converts its content to Markdown.
48
  visit_tool = VisitWebpageTool() # Defined in tools/visit_webpage.py
49
 
50
  # Define the model configuration using HfApiModel
51
  model = HfApiModel(
52
  max_tokens=2096,
53
  temperature=0.5,
54
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Adjust if this model is overloaded.
55
  custom_role_conversions=None,
56
  )
57
 
 
59
  with open("prompts.yaml", 'r') as stream:
60
  prompt_templates = yaml.safe_load(stream)
61
 
62
+ # Create the CodeAgent, including our working tools and the example tool.
63
  agent = CodeAgent(
64
  model=model,
65
  tools=[
66
  final_answer, # Must remain included.
67
  search_tool, # Enables web search.
68
  visit_tool, # Enables webpage visits.
69
+ get_current_time_in_timezone, # Working tool for time queries.
70
+ my_custom_tool, # Example (non-functioning) tool.
 
71
  ],
72
  max_steps=6,
73
  verbosity_level=1,