Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
os.system("pip install 'smolagents[openai]'") # ✅ Installa SmolAgents con OpenAI
|
3 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, OpenAIServerModel
|
4 |
import datetime
|
5 |
-
import wikipediaapi
|
6 |
import requests
|
7 |
import pytz
|
8 |
import yaml
|
@@ -42,25 +41,25 @@ final_answer = FinalAnswerTool()
|
|
42 |
# 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:
|
43 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
44 |
|
|
|
45 |
@tool
|
46 |
-
def
|
47 |
-
"""
|
48 |
|
49 |
Args:
|
50 |
-
query: The search term
|
51 |
-
lang: Language of the Wikipedia page (default: Italian).
|
52 |
|
53 |
Returns:
|
54 |
-
A
|
55 |
"""
|
56 |
-
|
57 |
-
|
58 |
-
page = wiki_wiki.page(query)
|
59 |
|
60 |
-
if not
|
61 |
-
return f"
|
62 |
|
63 |
-
|
|
|
64 |
|
65 |
|
66 |
model = OpenAIServerModel(
|
@@ -85,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
85 |
|
86 |
agent = CodeAgent(
|
87 |
model=model,
|
88 |
-
tools=[final_answer, get_current_time_in_timezone, image_generation_tool,
|
89 |
max_steps=6,
|
90 |
verbosity_level=1,
|
91 |
grammar=None,
|
|
|
2 |
os.system("pip install 'smolagents[openai]'") # ✅ Installa SmolAgents con OpenAI
|
3 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, OpenAIServerModel
|
4 |
import datetime
|
|
|
5 |
import requests
|
6 |
import pytz
|
7 |
import yaml
|
|
|
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.
|
48 |
|
49 |
Args:
|
50 |
+
query: The search term.
|
|
|
51 |
|
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(
|
|
|
84 |
|
85 |
agent = CodeAgent(
|
86 |
model=model,
|
87 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_duckduckgo],
|
88 |
max_steps=6,
|
89 |
verbosity_level=1,
|
90 |
grammar=None,
|