Surfnet commited on
Commit
669bdb8
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -1
app.py CHANGED
@@ -7,6 +7,8 @@ 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
@@ -34,6 +36,44 @@ def get_current_time_in_timezone(timezone: str) -> str:
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:
@@ -50,12 +90,15 @@ custom_role_conversions=None,
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
 
 
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(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,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+
11
+
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
36
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
37
 
38
 
39
+
40
+
41
+ ##########################
42
+ # Restaurant Tools #
43
+ ##########################
44
+
45
+ @tool
46
+
47
+ def summarize_top_pizza_places(search_results: str) -> str:
48
+ """
49
+ A tool that takes raw search results from DuckDuckGoSearchTool (in text form)
50
+ and attempts to figure out the top pizza place based on reviews or links.
51
+
52
+ Because the search results come in as text, we can parse or heuristically
53
+ find the best pizza place. Here we'll do a simplistic approach.
54
+ In a more advanced setup, you'd do real scraping or structured parsing.
55
+ Args:
56
+ search_results: The text returned by a search tool
57
+ Returns:
58
+ A short summary of the best pizza place or a guessed name.
59
+ """
60
+
61
+ lines = search_results.splitlines()
62
+ best_place = None
63
+
64
+ for line in lines:
65
+ if "best" in line.lower() or "top" in line.lower():
66
+ best_place = line
67
+ break
68
+
69
+ if best_place:
70
+ return f"I found a recommended pizza place: '{best_place}'"
71
+ else:
72
+ return f"I couldn't parse the top pizza place from these results. Maybe check manually?"
73
+
74
+
75
+
76
+
77
  final_answer = FinalAnswerTool()
78
 
79
  # 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:
 
90
  # Import tool from Hub
91
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
92
 
93
+ # DuckDuckGo Search tool for retrieving web search results
94
+ search_tool = DuckDuckGoSearchTool()
95
+
96
  with open("prompts.yaml", 'r') as stream:
97
  prompt_templates = yaml.safe_load(stream)
98
 
99
  agent = CodeAgent(
100
  model=model,
101
+ tools=[search_tool, summarize_top_pizza_places, image_generation_tool, final_answer]
102
  max_steps=6,
103
  verbosity_level=1,
104
  grammar=None,