Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -122,38 +122,40 @@ ti_tool = TextInspectorTool(model, text_limit)
|
|
122 |
browser = SimpleTextBrowser(**BROWSER_CONFIG)
|
123 |
|
124 |
|
125 |
-
class DuckDuckGoSearchTool(Tool):
|
126 |
"""Search tool using DuckDuckGo"""
|
127 |
name = "web_search"
|
128 |
description = "Search the web using DuckDuckGo (current information)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
def __init__(self, max_results: int = 5):
|
131 |
super().__init__()
|
132 |
self.max_results = max_results
|
133 |
|
134 |
def run(self, query: str) -> str:
|
135 |
-
"""Return formatted search results
|
136 |
try:
|
137 |
-
web_results = []
|
138 |
with DDGS() as ddgs:
|
139 |
-
|
140 |
-
web_results.append({
|
141 |
-
'title': result['title'],
|
142 |
-
'url': result['href'],
|
143 |
-
'content': result['body']
|
144 |
-
})
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
f"Content: {res['content'][:500]}{'...' if len(res['content']) > 500 else ''}"
|
152 |
-
)
|
153 |
-
return "\n\n".join(formatted_results)
|
154 |
except Exception as e:
|
155 |
return f"Search error: {str(e)}"
|
156 |
-
|
157 |
WEB_TOOLS = [
|
158 |
DuckDuckGoSearchTool(max_results=5),
|
159 |
VisitTool(browser),
|
@@ -164,7 +166,6 @@ WEB_TOOLS = [
|
|
164 |
ArchiveSearchTool(browser),
|
165 |
TextInspectorTool(model, text_limit),
|
166 |
]
|
167 |
-
|
168 |
# Agent creation in a factory function
|
169 |
def create_agent():
|
170 |
"""Creates a fresh agent instance for each session"""
|
@@ -325,4 +326,4 @@ Advanced question answering using DuckDuckGo search and custom AI models""")
|
|
325 |
demo.launch(debug=True, share=False, **kwargs)
|
326 |
|
327 |
if __name__ == "__main__":
|
328 |
-
GradioUI().launch()
|
|
|
122 |
browser = SimpleTextBrowser(**BROWSER_CONFIG)
|
123 |
|
124 |
|
125 |
+
class DuckDuckGoSearchTool(Tool):
|
126 |
"""Search tool using DuckDuckGo"""
|
127 |
name = "web_search"
|
128 |
description = "Search the web using DuckDuckGo (current information)"
|
129 |
+
inputs = [{
|
130 |
+
"name": "query",
|
131 |
+
"type": "string",
|
132 |
+
"description": "Search query string",
|
133 |
+
"required": True
|
134 |
+
}]
|
135 |
+
outputs = [{
|
136 |
+
"name": "results",
|
137 |
+
"type": "string",
|
138 |
+
"description": "Formatted search results"
|
139 |
+
}]
|
140 |
|
141 |
+
def __init__(self, max_results: int = 5):
|
142 |
super().__init__()
|
143 |
self.max_results = max_results
|
144 |
|
145 |
def run(self, query: str) -> str:
|
146 |
+
"""Return formatted search results"""
|
147 |
try:
|
|
|
148 |
with DDGS() as ddgs:
|
149 |
+
results = list(ddgs.text(query, max_results=self.max_results))
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
+
formatted = [
|
152 |
+
f"[{i+1}] {r['title']}\nURL: {r['href']}\n{r['body'][:500]}"
|
153 |
+
for i, r in enumerate(results)
|
154 |
+
]
|
155 |
+
return "\n\n".join(formatted)
|
|
|
|
|
|
|
156 |
except Exception as e:
|
157 |
return f"Search error: {str(e)}"
|
158 |
+
|
159 |
WEB_TOOLS = [
|
160 |
DuckDuckGoSearchTool(max_results=5),
|
161 |
VisitTool(browser),
|
|
|
166 |
ArchiveSearchTool(browser),
|
167 |
TextInspectorTool(model, text_limit),
|
168 |
]
|
|
|
169 |
# Agent creation in a factory function
|
170 |
def create_agent():
|
171 |
"""Creates a fresh agent instance for each session"""
|
|
|
326 |
demo.launch(debug=True, share=False, **kwargs)
|
327 |
|
328 |
if __name__ == "__main__":
|
329 |
+
GradioUI().launch()
|