Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,31 +7,57 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
!pip install duckduckgo-search --upgrade
|
11 |
+
|
12 |
+
from duckduckgo_search import DDGS
|
13 |
+
|
14 |
+
# Custom search tool class
|
15 |
+
class CustomDuckDuckGoSearchTool:
|
16 |
+
def __call__(self, query: str, max_results: int = 5):
|
17 |
+
try:
|
18 |
+
with DDGS() as ddgs:
|
19 |
+
results = []
|
20 |
+
for r in ddgs.text(query):
|
21 |
+
results.append(r)
|
22 |
+
if len(results) >= max_results:
|
23 |
+
break
|
24 |
+
return results
|
25 |
+
except Exception as e:
|
26 |
+
return f"Search error: {str(e)}"
|
27 |
+
|
28 |
+
# Dummy placeholder for `visit_webpage` tool
|
29 |
+
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 |
+
|
59 |
+
# Example usage
|
60 |
+
web_agent.run("Latest AI tools")
|
61 |
|
62 |
|
63 |
final_answer = FinalAnswerTool()
|