wt002 commited on
Commit
2495726
·
verified ·
1 Parent(s): 0c8074e
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -7,7 +7,9 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- !pip install duckduckgo-search --upgrade
 
 
11
 
12
  from duckduckgo_search import DDGS
13
 
@@ -30,29 +32,50 @@ class VisitWebpageTool:
30
  def __call__(self, url: str):
31
  return f"Pretending to visit: {url}"
32
 
33
- visit_webpage = VisitWebpageTool()
 
 
 
 
 
 
34
 
35
- # Dummy model and ToolCallingAgent setup
36
  class DummyModel:
37
  def call(self, input_text):
38
  return f"Model processing: {input_text}"
39
 
 
40
  class ToolCallingAgent:
41
- def __init__(self, tools, model, max_steps=10):
42
  self.tools = tools
43
  self.model = model
 
44
  self.max_steps = max_steps
45
 
46
  def run(self, query):
47
  print(f"Running agent with query: {query}")
 
48
  for tool in self.tools:
49
- print("Tool output:", tool(query))
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  # Initialize the agent
52
- model = DummyModel()
53
  web_agent = ToolCallingAgent(
54
- tools=[CustomDuckDuckGoSearchTool(), visit_webpage],
55
  model=model,
 
56
  max_steps=10
57
  )
58
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ pip install duckduckgo-search --upgrade
11
+
12
+ from duckduckgo_search import DDGS
13
 
14
  from duckduckgo_search import DDGS
15
 
 
32
  def __call__(self, url: str):
33
  return f"Pretending to visit: {url}"
34
 
35
+ # Final answer tool to format and return the final response
36
+ class FinalAnswerTool:
37
+ def __call__(self, results):
38
+ formatted_answer = "Final Answer:\n"
39
+ for result in results:
40
+ formatted_answer += f"- {str(result)}\n"
41
+ return formatted_answer
42
 
43
+ # Dummy model
44
  class DummyModel:
45
  def call(self, input_text):
46
  return f"Model processing: {input_text}"
47
 
48
+ # Modified ToolCallingAgent to use FinalAnswerTool
49
  class ToolCallingAgent:
50
+ def __init__(self, tools, model, final_answer_tool, max_steps=10):
51
  self.tools = tools
52
  self.model = model
53
+ self.final_answer_tool = final_answer_tool
54
  self.max_steps = max_steps
55
 
56
  def run(self, query):
57
  print(f"Running agent with query: {query}")
58
+ tool_outputs = []
59
  for tool in self.tools:
60
+ output = tool(query)
61
+ print("Tool output:", output)
62
+ tool_outputs.append(output)
63
+ # Use the final answer tool to format the collected outputs
64
+ final_result = self.final_answer_tool(tool_outputs)
65
+ print(final_result)
66
+ return final_result
67
+
68
+ # Initialize tools and model
69
+ model = DummyModel()
70
+ search_tool = CustomDuckDuckGoSearchTool()
71
+ visit_webpage = VisitWebpageTool()
72
+ final_answer = FinalAnswerTool()
73
 
74
  # Initialize the agent
 
75
  web_agent = ToolCallingAgent(
76
+ tools=[search_tool, visit_webpage],
77
  model=model,
78
+ final_answer_tool=final_answer,
79
  max_steps=10
80
  )
81