Raffaele Terribile
commited on
Implementa il primo agente
Browse files
app.py
CHANGED
|
@@ -4,23 +4,48 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, GoogleSearchTool, WebSearchTool, PythonInterpreterTool, WikipediaSearchTool, VisitWebpageTool
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# --- First Agent Definition ---
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
class FirstAgent:
|
| 16 |
### First Agent is the first attempt to develop an agent for the course. ###
|
| 17 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
print("FirstAgent initialized.")
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 21 |
-
|
| 22 |
-
print(f"Agent returning fixed answer: {
|
| 23 |
-
return
|
| 24 |
|
| 25 |
# --- Basic Agent Definition ---
|
| 26 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, GoogleSearchTool, WebSearchTool, PythonInterpreterTool, WikipediaSearchTool, VisitWebpageTool, FinalAnswerTool, Tool, tool
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
| 13 |
+
@tool
|
| 14 |
+
def invert_sentence(sentence: str) -> str:
|
| 15 |
+
"""
|
| 16 |
+
Inverts the order of all characters in a sentence.
|
| 17 |
+
"""
|
| 18 |
+
return sentence[::-1]
|
| 19 |
+
|
| 20 |
# --- First Agent Definition ---
|
| 21 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 22 |
class FirstAgent:
|
| 23 |
### First Agent is the first attempt to develop an agent for the course. ###
|
| 24 |
def __init__(self):
|
| 25 |
+
self.agent = CodeAgent(
|
| 26 |
+
tools=[
|
| 27 |
+
DuckDuckGoSearchTool(),
|
| 28 |
+
InferenceClientModel(),
|
| 29 |
+
GoogleSearchTool(),
|
| 30 |
+
WebSearchTool(),
|
| 31 |
+
PythonInterpreterTool(),
|
| 32 |
+
WikipediaSearchTool(),
|
| 33 |
+
VisitWebpageTool(),
|
| 34 |
+
FinalAnswerTool,
|
| 35 |
+
Tool(name="invert_sentence", func=invert_sentence, description="Inverts the order of characters in a sentence.")
|
| 36 |
+
],
|
| 37 |
+
verbose=True,
|
| 38 |
+
debug=True,
|
| 39 |
+
max_iterations=5,
|
| 40 |
+
max_tokens=1000,
|
| 41 |
+
temperature=0.7
|
| 42 |
+
)
|
| 43 |
print("FirstAgent initialized.")
|
| 44 |
def __call__(self, question: str) -> str:
|
| 45 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 46 |
+
answer = self.agent.run(question)
|
| 47 |
+
print(f"Agent returning fixed answer: {answer}")
|
| 48 |
+
return answer
|
| 49 |
|
| 50 |
# --- Basic Agent Definition ---
|
| 51 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|