altozachmo commited on
Commit
0d91eab
·
1 Parent(s): 4ace2c3

improve prompt

Browse files
agents/__init__.py CHANGED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import (
2
+ DuckDuckGoSearchTool,
3
+ VisitWebpageTool,
4
+ WikipediaSearchTool,
5
+ )
6
+ from tools.text_search import TextSearch
7
+ from tools.text_splitter import text_splitter
8
+ from tools.webpage_parser import WebpageParser
9
+ from tools.parse_wikipedia_table import WikipediaParser
10
+ from tools.open_files import OpenFilesTool
11
+
12
+ DEFAULT_ARGS = myagent_args = {
13
+ "provider": "litellm",
14
+ "model_id": "gemini/gemini-2.0-flash-lite",
15
+ # "api_base": OLLAMA_API_BASE,
16
+ "planning_interval": 3,
17
+ "add_base_tools": True,
18
+ "tools": [
19
+ DuckDuckGoSearchTool(),
20
+ WikipediaParser(),
21
+ VisitWebpageTool(),
22
+ TextSearch(),
23
+ text_splitter,
24
+ WikipediaSearchTool(
25
+ content_type="text",
26
+ extract_format="HTML"
27
+ ),
28
+ WebpageParser(),
29
+ OpenFilesTool(),
30
+ ],
31
+ "additional_authorized_imports": [
32
+ "pandas",
33
+ "numpy",
34
+ "datetime",
35
+ "json",
36
+ "re",
37
+ "math",
38
+ "os",
39
+ "requests",
40
+ "csv",
41
+ "urllib",
42
+ ],
43
+ "num_ctx": 128_000,
44
+ "temperature": 0.2,
45
+ }
agents/agent.py CHANGED
@@ -86,6 +86,6 @@ class MyAgent:
86
  """
87
 
88
  final_answer = self.agent.run(question)
89
- print(f"Agent received question (first 50 chars): {question[:50]}...")
90
  print(f"Agent returning fixed answer: {final_answer}")
91
  return final_answer
 
86
  """
87
 
88
  final_answer = self.agent.run(question)
89
+ print(f"Agent received question (last 50 chars): {question[-50:]}...")
90
  print(f"Agent returning fixed answer: {final_answer}")
91
  return final_answer
app.py CHANGED
@@ -6,49 +6,11 @@ from agents.agent import MyAgent
6
  import time
7
  from tqdm import tqdm
8
  from prompts.default_prompt import generate_prompt
9
- from smolagents import (
10
- DuckDuckGoSearchTool,
11
- VisitWebpageTool,
12
- )
13
- from tools.text_search import TextSearch
14
- from tools.text_splitter import text_splitter
15
- from tools.webpage_parser import WebpageParser
16
- from tools.parse_wikipedia_table import WikipediaParser
17
- from tools.open_files import OpenFilesTool
18
 
19
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
20
 
21
 
22
- myagent_args = {
23
- "provider": "litellm",
24
- "model_id": "gemini/gemini-2.0-flash-lite",
25
- # "api_base": OLLAMA_API_BASE,
26
- "planning_interval": 3,
27
- "tools": [
28
- DuckDuckGoSearchTool(),
29
- WikipediaParser(),
30
- VisitWebpageTool(),
31
- TextSearch(),
32
- text_splitter,
33
- WebpageParser(),
34
- OpenFilesTool(),
35
- ],
36
- "additional_authorized_imports": [
37
- "pandas",
38
- "numpy",
39
- "datetime",
40
- "json",
41
- "re",
42
- "math",
43
- "os",
44
- "requests",
45
- "csv",
46
- "urllib",
47
- ],
48
- "num_ctx": 8192,
49
- "temperature": 0.2,
50
- }
51
-
52
 
53
  def run_and_submit_all(profile: gr.OAuthProfile | None):
54
  """
@@ -71,7 +33,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
71
 
72
  # 1. Instantiate Agent ( modify this part to create your agent)
73
  try:
74
- agent = MyAgent(**myagent_args)
75
 
76
  except Exception as e:
77
  print(f"Error instantiating agent: {e}")
 
6
  import time
7
  from tqdm import tqdm
8
  from prompts.default_prompt import generate_prompt
9
+ from agents import DEFAULT_ARGS
 
 
 
 
 
 
 
 
10
 
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def run_and_submit_all(profile: gr.OAuthProfile | None):
16
  """
 
33
 
34
  # 1. Instantiate Agent ( modify this part to create your agent)
35
  try:
36
+ agent = MyAgent(**DEFAULT_ARGS)
37
 
38
  except Exception as e:
39
  print(f"Error instantiating agent: {e}")
prompts/default_prompt.py CHANGED
@@ -15,20 +15,14 @@ def generate_prompt(question_text, file_name):
15
  When given a question:
16
  - If necessary, perform a web search using the tool `DuckDuckGoSearchTool` to find possible sources of information.
17
  - Use the `visit_webpage` tool to visit the webpage and extract the content in markdown format.
18
- - If the web search only returns titles and short snippets, you MUST visit the actual webpage to read the full content before answering.
19
- - Use the `WikipediaParser` tool to fetch and read the Wikipedia page when necessary.
20
- - You just have the ability to read Wikipedia pages only.
21
- - If the task requires reading, listening, or analyzing a file, you must use the file specified in the `file_name` field of the task metadata, not the file name mentioned casually inside the question text.
22
- - Comma separated lists MUST contain a single space after each comma.
23
- - If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
24
- - If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
25
- - If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
26
- - Only answer after you have gathered enough information by reading the actual page contents.
27
  - Once you have the final answer, you must call `final_answer("your_answer")` immediately after printing it.
28
  - Do not retry or execute anything else after calling `final_answer`.
29
- - `final_answer` must wrap the exact printed value.
30
- Provide ONLY the precise answer requested.
31
- Do not include explanations, steps, reasoning, or additional text.
32
  Be direct and specific. GAIA benchmark requires exact matching answers.
33
  Example: if asked "What is the capital of France?", respond exactly:
34
  Thoughts: I need to retrieve the capital of France from Wikipedia and output it directly.
 
15
  When given a question:
16
  - If necessary, perform a web search using the tool `DuckDuckGoSearchTool` to find possible sources of information.
17
  - Use the `visit_webpage` tool to visit the webpage and extract the content in markdown format.
18
+ - Use the `WikipediaSearchTool` to search for any information on Wikipedia, this will return HTML content. You need to then use the `WikipediaParser` tool to parse the HTML content into a clean, readable text format.
19
+ - If the file_name provided ends in ".py", use the `PythonInterpreterTool` to execute the code in the file and return the output.
20
+ - Use the `PythonInterpreterTool` to execute any Python code snippets you generate.
21
+ - Use the `TextSearch` tool to search for a substring within a string.
22
+ - Use the `text_splitter` tool to split a string into smaller chunks of text.
23
+ - If the task requires reading, listening, or analyzing a file, you must use the file specified in the `file_name` field of the task metadata, not the file name mentioned casually inside the question text. Use the `OpenFilesTool` to open the file and read its content.
 
 
 
24
  - Once you have the final answer, you must call `final_answer("your_answer")` immediately after printing it.
25
  - Do not retry or execute anything else after calling `final_answer`.
 
 
 
26
  Be direct and specific. GAIA benchmark requires exact matching answers.
27
  Example: if asked "What is the capital of France?", respond exactly:
28
  Thoughts: I need to retrieve the capital of France from Wikipedia and output it directly.
run_local_agent.py CHANGED
@@ -11,6 +11,7 @@ from tools.webpage_parser import WebpageParser
11
  from tools.parse_wikipedia_table import WikipediaParser
12
  from tools.open_files import OpenFilesTool
13
  from prompts.default_prompt import generate_prompt
 
14
 
15
 
16
  import os
@@ -56,10 +57,10 @@ myagent_args = {
56
  "temperature": 0.2,
57
  }
58
 
59
- print(f"Using args: {myagent_args}")
60
 
61
  if __name__ == "__main__":
62
- agent = MyAgent(**myagent_args)
63
 
64
  with open(QUESTIONS_FILEPATH, "r") as f:
65
  questions = json.load(f)
 
11
  from tools.parse_wikipedia_table import WikipediaParser
12
  from tools.open_files import OpenFilesTool
13
  from prompts.default_prompt import generate_prompt
14
+ from agents import DEFAULT_ARGS
15
 
16
 
17
  import os
 
57
  "temperature": 0.2,
58
  }
59
 
60
+ print(f"Using args: {DEFAULT_ARGS}")
61
 
62
  if __name__ == "__main__":
63
+ agent = MyAgent(**DEFAULT_ARGS)
64
 
65
  with open(QUESTIONS_FILEPATH, "r") as f:
66
  questions = json.load(f)
tools/parse_wikipedia_table.py CHANGED
@@ -26,7 +26,7 @@ class WikipediaParser(Tool):
26
  """
27
 
28
  headers = {
29
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" # AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
30
  }
31
  resp = requests.get(url, headers=headers, timeout=30)
32
  resp.raise_for_status()
@@ -49,7 +49,7 @@ class WikipediaParser(Tool):
49
  elif elem.name == "table":
50
  elements.append(self.parse_wikipedia_table(elem))
51
 
52
- return "\n".join(elements)
53
 
54
  def parse_wikipedia_table(table: Tag) -> str:
55
  """
 
26
  """
27
 
28
  headers = {
29
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
30
  }
31
  resp = requests.get(url, headers=headers, timeout=30)
32
  resp.raise_for_status()
 
49
  elif elem.name == "table":
50
  elements.append(self.parse_wikipedia_table(elem))
51
 
52
+ return "\n\n".join(elements)
53
 
54
  def parse_wikipedia_table(table: Tag) -> str:
55
  """