Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,16 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, FinalAnswerTool
|
| 7 |
from tools import TextTransformerTool
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
@@ -19,32 +28,48 @@ import os
|
|
| 19 |
from smolagents import HfApiModel
|
| 20 |
|
| 21 |
|
|
|
|
| 22 |
class BasicAgent:
|
| 23 |
def __init__(self):
|
| 24 |
print("Initializing BasicAgent with tools...")
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
if not
|
| 29 |
-
raise ValueError("Missing
|
| 30 |
-
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
search_tool = DuckDuckGoSearchTool()
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
self.agent = CodeAgent(
|
| 38 |
model=model,
|
| 39 |
-
|
|
|
|
| 40 |
add_base_tools=True,
|
| 41 |
-
planning_interval=
|
| 42 |
-
|
|
|
|
| 43 |
verbosity_level=1,
|
| 44 |
)
|
| 45 |
|
| 46 |
def __call__(self, question: str) -> str:
|
| 47 |
-
print(f"Agent received question (first 50 chars): {question
|
| 48 |
answer = self.agent(question)
|
| 49 |
print(f"Agent returning answer: {answer}")
|
| 50 |
return answer
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, FinalAnswerTool
|
| 7 |
from tools import TextTransformerTool
|
| 8 |
+
import os
|
| 9 |
+
import yaml
|
| 10 |
+
from tools_agent import ReverseTextTool, TableCommutativityTool, VegetableListTool, ExcelSumFoodTool
|
| 11 |
+
from smolagents import (
|
| 12 |
+
CodeAgent,
|
| 13 |
+
OpenAIServerModel,
|
| 14 |
+
DuckDuckGoSearchTool,
|
| 15 |
+
FinalAnswerTool,
|
| 16 |
+
PythonInterpreterTool
|
| 17 |
+
)
|
| 18 |
|
| 19 |
# (Keep Constants as is)
|
| 20 |
# --- Constants ---
|
|
|
|
| 28 |
from smolagents import HfApiModel
|
| 29 |
|
| 30 |
|
| 31 |
+
# --- Agent Definition ---
|
| 32 |
class BasicAgent:
|
| 33 |
def __init__(self):
|
| 34 |
print("Initializing BasicAgent with tools...")
|
| 35 |
|
| 36 |
+
# Load OpenAI token from environment
|
| 37 |
+
openai_token = os.getenv("OPENAI_API_KEY")
|
| 38 |
+
if not openai_token:
|
| 39 |
+
raise ValueError("Missing OpenAI API token!")
|
| 40 |
+
|
| 41 |
+
# Initialize model and tools
|
| 42 |
+
model = OpenAIServerModel(
|
| 43 |
+
#api_base="openai",
|
| 44 |
+
api_key=openai_token,
|
| 45 |
+
model_id="gpt-4.1"
|
| 46 |
+
)
|
| 47 |
search_tool = DuckDuckGoSearchTool()
|
| 48 |
+
final_answer_tool = FinalAnswerTool()
|
| 49 |
+
reverse_tool = ReverseTextTool()
|
| 50 |
+
table_tool = TableCommutativityTool()
|
| 51 |
+
veg_tool = VegetableListTool()
|
| 52 |
+
python_tool = PythonInterpreterTool()
|
| 53 |
+
exfood_tool = ExcelSumFoodTool()
|
| 54 |
+
|
| 55 |
+
# Load system prompt templates
|
| 56 |
+
with open("prompts.yaml", "r") as stream:
|
| 57 |
+
prompt_templates = yaml.safe_load(stream)
|
| 58 |
+
|
| 59 |
+
# Build the agent
|
| 60 |
self.agent = CodeAgent(
|
| 61 |
model=model,
|
| 62 |
+
prompt_templates=prompt_templates,
|
| 63 |
+
tools=[search_tool, reverse_tool, table_tool, veg_tool, python_tool, exfood_tool, final_answer_tool], #final_answer_tool
|
| 64 |
add_base_tools=True,
|
| 65 |
+
planning_interval=None,
|
| 66 |
+
name = "GoodAgent",
|
| 67 |
+
max_steps=10,
|
| 68 |
verbosity_level=1,
|
| 69 |
)
|
| 70 |
|
| 71 |
def __call__(self, question: str) -> str:
|
| 72 |
+
print(f"Agent received question (first 50 chars): {question}...")
|
| 73 |
answer = self.agent(question)
|
| 74 |
print(f"Agent returning answer: {answer}")
|
| 75 |
return answer
|