Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, BitsAndB
|
|
14 |
from smolagents import CodeAgent, VisitWebpageTool, WebSearchTool, WikipediaSearchTool, PythonInterpreterTool
|
15 |
from smolagents.models import ChatMessage
|
16 |
from custom_tools import WebpageStructureAnalyzerTool
|
|
|
17 |
|
18 |
subprocess.run(["playwright", "install"], check=True)
|
19 |
|
@@ -197,9 +198,20 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
197 |
search_tool = CachedWebSearchTool()
|
198 |
python_tool = PythonInterpreterTool()
|
199 |
html_parse_tool = VisitWebpageTool()
|
200 |
-
#(3) Create the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
agent = CodeAgent(model=llm_model,
|
202 |
tools=[web_structure_analyzer_tool, wiki_tool, search_tool, python_tool, html_parse_tool],
|
|
|
203 |
max_steps=5,
|
204 |
add_base_tools=True,
|
205 |
additional_authorized_imports=["dateparser", "bs4", "regex"])
|
|
|
14 |
from smolagents import CodeAgent, VisitWebpageTool, WebSearchTool, WikipediaSearchTool, PythonInterpreterTool
|
15 |
from smolagents.models import ChatMessage
|
16 |
from custom_tools import WebpageStructureAnalyzerTool
|
17 |
+
from system_prompts import CODE_AGENT_DEFAULT_SYSTEM_PROMPTS
|
18 |
|
19 |
subprocess.run(["playwright", "install"], check=True)
|
20 |
|
|
|
198 |
search_tool = CachedWebSearchTool()
|
199 |
python_tool = PythonInterpreterTool()
|
200 |
html_parse_tool = VisitWebpageTool()
|
201 |
+
# (3) Create the system prompt
|
202 |
+
my_added_prompts = """
|
203 |
+
When you receive output from a tool (like wiki_tool or html_parse_tool), do not include the entire raw output in your next thought if it is very long.
|
204 |
+
Instead, first analyze it (possibly using another tool or by writing code to extract key parts) and only include essential snippets, summaries, or the extracted data relevant to your current plan in your thoughts and observations.
|
205 |
+
ALL executable Python code that you want to run with the PythonInterpreterTool MUST be enclosed in triple backticks with 'py' like this: ```py\n# your python code here\n```
|
206 |
+
Do NOT write any explanations outside of Python comments within these code blocks.
|
207 |
+
Your thoughts and reasoning should precede the code block.
|
208 |
+
For web pages, always use web_structure_analyzer_tool to understand the page's layout before attempting to write detailed parsing code with bs4.
|
209 |
+
"""
|
210 |
+
combined_system_prompt = CODE_AGENT_DEFAULT_SYSTEM_PROMPTS + "\n\n" + added_prompts
|
211 |
+
# (4) Create the CodeAgent, passing the LLM wrapper and tools
|
212 |
agent = CodeAgent(model=llm_model,
|
213 |
tools=[web_structure_analyzer_tool, wiki_tool, search_tool, python_tool, html_parse_tool],
|
214 |
+
system_prompt=combined_system_prompt,
|
215 |
max_steps=5,
|
216 |
add_base_tools=True,
|
217 |
additional_authorized_imports=["dateparser", "bs4", "regex"])
|