Atualizando agente com smolagent
#198
by
v1nybarreto
- opened
app.py
CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -12,12 +14,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
print("
|
|
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
print(f"
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagent import CodeAgent
|
7 |
+
from smolagent.tools.python import PythonInterpreterTool
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
|
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
class BasicAgent:
|
16 |
def __init__(self):
|
17 |
+
print("🔧 Inicializando CodeAgent com ferramenta Python.")
|
18 |
+
tools = [PythonInterpreterTool()]
|
19 |
+
self.agent = CodeAgent(tools=tools)
|
20 |
+
|
21 |
def __call__(self, question: str) -> str:
|
22 |
+
print(f"🤖 Pergunta recebida: {question[:100]}")
|
23 |
+
response = self.agent.run(question)
|
24 |
+
|
25 |
+
if "FINAL ANSWER:" in response:
|
26 |
+
answer = response.split("FINAL ANSWER:")[-1].strip()
|
27 |
+
else:
|
28 |
+
answer = response.strip()
|
29 |
+
|
30 |
+
print(f"✅ Resposta final: {answer}")
|
31 |
+
return answer
|
32 |
|
33 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
34 |
"""
|