henryk commited on
Commit
508c2d1
·
verified ·
1 Parent(s): 5675ecd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -15
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
- from smolagents import InferenceClientModel
 
 
 
 
 
 
 
 
 
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
- # Ensure the token is available
27
- hf_token = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
28
- if not hf_token:
29
- raise ValueError("Missing Hugging Face API token!")
30
- openai_token = os.environ.get("OPENAI_API_KEY")
31
- # Pass it into the model
32
- # model = HfApiModel(model="mistralai/Mistral-7B-Instruct-v0.2") #token=hf_token,
33
- model = InferenceClientModel(provider="openai", token=openai_token, model_id="gpt-3.5-turbo")
 
 
 
34
  search_tool = DuckDuckGoSearchTool()
35
- text_tool = TextTransformerTool()
36
- final_answer = FinalAnswerTool()
 
 
 
 
 
 
 
 
 
 
37
  self.agent = CodeAgent(
38
  model=model,
39
- tools=[search_tool, text_tool, final_answer],
 
40
  add_base_tools=True,
41
- planning_interval=2,
42
- max_steps=6,
 
43
  verbosity_level=1,
44
  )
45
 
46
  def __call__(self, question: str) -> str:
47
- print(f"Agent received question (first 50 chars): {question[:50]}...")
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