Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,27 +9,31 @@ 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 crypto_duck(addr: str) -> str:
|
| 13 |
-
"""Search DuckDuckGo for information about a cryptocurrency address and return the top result.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
ddg = DuckDuckGoSearchTool(max_results=1)
|
| 16 |
query = f'cryptocurrency address "{addr}"'
|
| 17 |
-
#
|
| 18 |
-
if hasattr(ddg, "run")
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
res = ddg(query)
|
| 22 |
-
# res may already be a string; if it’s a list of dicts, format the first
|
| 23 |
if isinstance(res, list) and res:
|
| 24 |
top = res[0]
|
| 25 |
title = top.get("title", "")
|
| 26 |
href = top.get("href") or top.get("link", "")
|
| 27 |
snippet = top.get("body") or top.get("snippet", "")
|
| 28 |
return f"{title}\n{snippet}\n{href}".strip()
|
|
|
|
|
|
|
| 29 |
if isinstance(res, str):
|
| 30 |
-
if res.startswith("## Search Results")
|
| 31 |
-
|
| 32 |
-
return res or "No results found."
|
| 33 |
return "No results found."
|
| 34 |
except Exception as e:
|
| 35 |
return f"Search error: {str(e)}"
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
@tool
|
| 13 |
def crypto_duck(addr: str) -> str:
|
| 14 |
+
"""Search DuckDuckGo for information about a cryptocurrency address and return the top result.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
addr: The cryptocurrency address to search for (e.g., a Bitcoin or Ethereum address).
|
| 18 |
+
"""
|
| 19 |
try:
|
| 20 |
ddg = DuckDuckGoSearchTool(max_results=1)
|
| 21 |
query = f'cryptocurrency address "{addr}"'
|
| 22 |
+
# Support both callable and .run signatures across versions
|
| 23 |
+
res = ddg.run(query=query) if hasattr(ddg, "run") else ddg(query)
|
| 24 |
+
|
| 25 |
+
# If the tool returns a list[dict], format the first result
|
|
|
|
|
|
|
| 26 |
if isinstance(res, list) and res:
|
| 27 |
top = res[0]
|
| 28 |
title = top.get("title", "")
|
| 29 |
href = top.get("href") or top.get("link", "")
|
| 30 |
snippet = top.get("body") or top.get("snippet", "")
|
| 31 |
return f"{title}\n{snippet}\n{href}".strip()
|
| 32 |
+
|
| 33 |
+
# If it returns a markdown string, strip any header the custom class adds
|
| 34 |
if isinstance(res, str):
|
| 35 |
+
return res.split("\n\n", 1)[-1] if res.startswith("## Search Results") else (res or "No results found.")
|
| 36 |
+
|
|
|
|
| 37 |
return "No results found."
|
| 38 |
except Exception as e:
|
| 39 |
return f"Search error: {str(e)}"
|