Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ 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 requests
|
6 |
import pytz
|
7 |
import yaml
|
@@ -41,6 +42,25 @@ 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 |
model = OpenAIServerModel(
|
46 |
max_tokens=2096,
|
@@ -64,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
64 |
|
65 |
agent = CodeAgent(
|
66 |
model=model,
|
67 |
-
tools=[final_answer, get_current_time_in_timezone, image_generation_tool],
|
68 |
max_steps=6,
|
69 |
verbosity_level=1,
|
70 |
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 wikipediaapi
|
6 |
import requests
|
7 |
import pytz
|
8 |
import yaml
|
|
|
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 search_wikipedia(query: str, lang: str = "it") -> str:
|
47 |
+
"""Fetches a summary from Wikipedia for a given topic.
|
48 |
+
|
49 |
+
Args:
|
50 |
+
query: The search term for Wikipedia.
|
51 |
+
lang: Language of the Wikipedia page (default: Italian).
|
52 |
+
|
53 |
+
Returns:
|
54 |
+
A short summary from Wikipedia.
|
55 |
+
"""
|
56 |
+
wiki_wiki = wikipediaapi.Wikipedia(lang) # Creiamo un'istanza di Wikipedia in italiano
|
57 |
+
page = wiki_wiki.page(query) # Cerchiamo la pagina
|
58 |
+
|
59 |
+
if not page.exists():
|
60 |
+
return f"Nessuna pagina trovata per '{query}' su Wikipedia."
|
61 |
+
|
62 |
+
return page.summary[:500] + "..." # Restituiamo un riassunto di massimo 500 caratteri
|
63 |
+
|
64 |
|
65 |
model = OpenAIServerModel(
|
66 |
max_tokens=2096,
|
|
|
84 |
|
85 |
agent = CodeAgent(
|
86 |
model=model,
|
87 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_wikipedia],
|
88 |
max_steps=6,
|
89 |
verbosity_level=1,
|
90 |
grammar=None,
|