keynes42 commited on
Commit
84f4310
·
verified ·
1 Parent(s): 5d255b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -11,7 +11,7 @@ import pandas as pd
11
  import torch
12
  from functools import lru_cache
13
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
14
- from smolagents import CodeAgent, WebSearchTool, WikipediaSearchTool, VisitWebpageTool, PythonInterpreterTool
15
  import smolagents.tools as _tools
16
  from smolagents.models import ChatMessage
17
  # from huggingface_hub import InferenceClient, hf_hub_download
@@ -137,14 +137,20 @@ class BasicAgent:
137
  search_tool = CachedWebSearchTool()
138
  python_tool = PreloadedPythonTool()
139
  html_parse_tool = VisitWebpageTool()
 
 
 
 
 
 
 
 
140
  # Initialize the agent
141
  self.agent = CodeAgent(model=self,
142
  tools=[wiki_tool, search_tool, python_tool, html_parse_tool],
143
  add_base_tools=True,
144
- additional_authorized_imports=["dateparser", "bs4", "regex"],
145
- system_message=("When writing Python code in the PythonInterpreterTool, you must "
146
- "always import bs4 and regex (already preloaded), and *return* your "
147
- "result by calling final_answer(...). Do not assign to a variable named final_answer.")
148
  )
149
 
150
  def _serialize_messages(self, messages):
 
11
  import torch
12
  from functools import lru_cache
13
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
14
+ from smolagents import PromptTemplates, CodeAgent, WebSearchTool, WikipediaSearchTool, VisitWebpageTool, PythonInterpreterTool
15
  import smolagents.tools as _tools
16
  from smolagents.models import ChatMessage
17
  # from huggingface_hub import InferenceClient, hf_hub_download
 
137
  search_tool = CachedWebSearchTool()
138
  python_tool = PreloadedPythonTool()
139
  html_parse_tool = VisitWebpageTool()
140
+ # System prompt
141
+ my_templates = PromptTemplates(
142
+ system_prompt=(
143
+ "When writing Python code in the PythonInterpreterTool,"
144
+ "you must always import bs4 and regex (already preloaded),"
145
+ "and *return* your result by calling final_answer(...). Do not assign to a variable named final_answer."
146
+ )
147
+ )
148
  # Initialize the agent
149
  self.agent = CodeAgent(model=self,
150
  tools=[wiki_tool, search_tool, python_tool, html_parse_tool],
151
  add_base_tools=True,
152
+ prompt_templates=my_templates,
153
+ additional_authorized_imports=["dateparser", "bs4", "regex"]
 
 
154
  )
155
 
156
  def _serialize_messages(self, messages):