Ubik80 commited on
Commit
af4dc02
·
verified ·
1 Parent(s): 255f737

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
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
- # 1️⃣ Creiamo il Tool di ricerca su DuckDuckGo
 
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() # ✅ Inizializza il motore di ricerca
56
- results = search_tool(query) # 🔍 Esegue la ricerca
 
 
57
 
58
  if not results:
59
  return f"Nessun risultato trovato per '{query}'."
60
 
61
- top_result = results[0] # 📌 Prendiamo il primo risultato
62
- return f"🔎 {top_result['title']}\n{top_result['snippet']}\n🔗 {top_result['link']}"
 
 
 
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(