Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,8 @@ final_answer = FinalAnswerTool()
|
|
| 41 |
# 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:
|
| 42 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 43 |
|
| 44 |
-
|
|
|
|
| 45 |
@tool
|
| 46 |
def search_duckduckgo(query: str) -> str:
|
| 47 |
"""Performs a web search using DuckDuckGo and returns the first result summary.
|
|
@@ -52,14 +53,19 @@ def search_duckduckgo(query: str) -> str:
|
|
| 52 |
Returns:
|
| 53 |
A summary of the first result found.
|
| 54 |
"""
|
| 55 |
-
search_tool = DuckDuckGoSearchTool()
|
| 56 |
-
results = search_tool(query) # 🔍
|
|
|
|
|
|
|
| 57 |
|
| 58 |
if not results:
|
| 59 |
return f"Nessun risultato trovato per '{query}'."
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
model = OpenAIServerModel(
|
|
|
|
| 41 |
# 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:
|
| 42 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 43 |
|
| 44 |
+
from smolagents import tool, DuckDuckGoSearchTool
|
| 45 |
+
|
| 46 |
@tool
|
| 47 |
def search_duckduckgo(query: str) -> str:
|
| 48 |
"""Performs a web search using DuckDuckGo and returns the first result summary.
|
|
|
|
| 53 |
Returns:
|
| 54 |
A summary of the first result found.
|
| 55 |
"""
|
| 56 |
+
search_tool = DuckDuckGoSearchTool()
|
| 57 |
+
results = search_tool(query) # 🔍 Effettua la ricerca su DuckDuckGo
|
| 58 |
+
|
| 59 |
+
print("DEBUG - Risultati della ricerca:", results) # 🚨 Debug: Stampiamo il formato dei dati ricevuti
|
| 60 |
|
| 61 |
if not results:
|
| 62 |
return f"Nessun risultato trovato per '{query}'."
|
| 63 |
|
| 64 |
+
if isinstance(results, list): # ✅ Se i risultati sono una lista, allora selezioniamo il primo risultato
|
| 65 |
+
top_result = results[0]
|
| 66 |
+
return f"🔎 {top_result.get('title', 'Nessun titolo')}\n{top_result.get('snippet', 'Nessuna descrizione')}\n🔗 {top_result.get('link', 'Nessun link')}"
|
| 67 |
+
else:
|
| 68 |
+
return f"Errore: il formato dei dati non è quello previsto. Ecco il contenuto: {results}"
|
| 69 |
|
| 70 |
|
| 71 |
model = OpenAIServerModel(
|