Andrei Nazarov commited on
Commit
3657cd4
·
1 Parent(s): 828c9ee

updated prompt

Browse files
Files changed (3) hide show
  1. __pycache__/tools.cpython-310.pyc +0 -0
  2. app.py +42 -5
  3. tools.py +27 -5
__pycache__/tools.cpython-310.pyc CHANGED
Binary files a/__pycache__/tools.cpython-310.pyc and b/__pycache__/tools.cpython-310.pyc differ
 
app.py CHANGED
@@ -62,6 +62,15 @@ class GeminiModel(Model):
62
  - Be precise about dates, numbers, and classifications
63
  - If information seems unclear or contradictory, search for additional sources
64
  - When counting items, be explicit about what you're counting and why
 
 
 
 
 
 
 
 
 
65
 
66
  **YOUR TOOLS**
67
  - `web_search(query: str)`: Finds URLs and information.
@@ -90,20 +99,20 @@ web_search(query="Mercedes Sosa studio albums discography 2000-2009")
90
  *Observation:* Search results show various sources including Wikipedia, AllMusic, and other music databases.
91
 
92
  **Your Turn 2:**
93
- Thought: I need to check multiple sources to ensure accuracy. Let me visit a reliable music database.
94
  Code:
95
  ```py
96
- visit_webpage(url="https://www.allmusic.com/artist/mercedes-sosa-mn0000869068")
97
  ```<end_code>
98
- *Observation:* The AllMusic page shows studio albums with release dates. I can see: Corazón Libre (2005), Cantora 1 (2009), Cantora 2 (2009).
99
 
100
  **Your Turn 3:**
101
  Thought: I found 3 studio albums in the specified period. Let me verify this with another source to be sure.
102
  Code:
103
  ```py
104
- visit_webpage(url="https://en.wikipedia.org/wiki/Mercedes_Sosa")
105
  ```<end_code>
106
- *Observation:* The Wikipedia page confirms the same 3 studio albums in the discography section.
107
 
108
  **Your Turn 4:**
109
  Thought: I have verified from multiple sources that there are exactly 3 studio albums: Corazón Libre (2005), Cantora 1 (2009), and Cantora 2 (2009).
@@ -111,6 +120,34 @@ Code:
111
  ```py
112
  final_answer("3")
113
  ```<end_code>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  """
115
 
116
  def generate(
 
62
  - Be precise about dates, numbers, and classifications
63
  - If information seems unclear or contradictory, search for additional sources
64
  - When counting items, be explicit about what you're counting and why
65
+ - **UNDERSTAND CONTEXT AND SYNONYMS**: When searching for specific terms, also look for related terms, synonyms, and contextual descriptions
66
+ - **READ FOR CONTEXT**: Don't just search for exact phrases - read the content to understand who or what is being described
67
+ - **CONSIDER ALTERNATIVE TERMINOLOGY**: "Horse doctor" = "equine veterinarian", "physician" = "doctor", etc.
68
+ - **BREAK DOWN COMPLEX QUESTIONS**: For questions with multiple steps, identify each step clearly:
69
+ 1. What is the first thing I need to find?
70
+ 2. What is the second thing I need to find using the first result?
71
+ 3. What is the final answer I need to provide?
72
+ - **FOLLOW THE LOGICAL CHAIN**: Don't jump to conclusions - follow each step in order
73
+ - Don't take the final answera from web results preview, always read the full content of the page
74
 
75
  **YOUR TOOLS**
76
  - `web_search(query: str)`: Finds URLs and information.
 
99
  *Observation:* Search results show various sources including Wikipedia, AllMusic, and other music databases.
100
 
101
  **Your Turn 2:**
102
+ Thought: I need to check multiple sources to ensure accuracy. Let me visit Wikipedia.
103
  Code:
104
  ```py
105
+ visit_webpage(url="https://en.wikipedia.org/wiki/Mercedes_Sosa")
106
  ```<end_code>
107
+ *Observation:* The Wikipedia page shows studio albums with release dates. I can see: Corazón Libre (2005), Cantora 1 (2009), Cantora 2 (2009).
108
 
109
  **Your Turn 3:**
110
  Thought: I found 3 studio albums in the specified period. Let me verify this with another source to be sure.
111
  Code:
112
  ```py
113
+ visit_webpage(url="https://www.allmusic.com/artist/mercedes-sosa-mn0000869068#discography")
114
  ```<end_code>
115
+ *Observation:* AllMusic shows more albums in the discography section between 2000 and 2009: Acustico (2002), Maestros del Folklore (2003), Argentina Quiere Cantar (2003), Para Cantar He Nacido (2005), Corazón Libre (2005), Acustico Na Suica (2007), Acustico en Suiza Inedito (2009), Cantora, Vol. 2 (2009). But it doesn't show the album type - studio, live or something else. I can assume that the 3 studio albums are the albums mentionCorazón Libre (2005), Cantora 1 (2009), and Cantora 2 (2009).
116
 
117
  **Your Turn 4:**
118
  Thought: I have verified from multiple sources that there are exactly 3 studio albums: Corazón Libre (2005), Cantora 1 (2009), and Cantora 2 (2009).
 
120
  ```py
121
  final_answer("3")
122
  ```<end_code>
123
+
124
+ ---
125
+ **EXAMPLE 3: Understanding Context and Alternative Terms**
126
+ *Question:* What is the surname of the equine veterinarian mentioned in the LibreTexts chemistry exercises?
127
+
128
+ **Your Turn 1:**
129
+ Thought: I need to find the LibreTexts chemistry exercises and look for mentions of an equine veterinarian. I should also search for related terms like "horse doctor" or "veterinarian" since the exact phrase might not be used.
130
+ Code:
131
+ ```py
132
+ web_search(query="LibreTexts chemistry exercises equine veterinarian horse doctor")
133
+ ```<end_code>
134
+ *Observation:* Search results show the LibreTexts exercises page.
135
+
136
+ **Your Turn 2:**
137
+ Thought: I found the exercises page. Now I need to read the content carefully, looking not just for "equine veterinarian" but also for related terms and contextual descriptions of someone who treats horses.
138
+ Code:
139
+ ```py
140
+ visit_webpage(url="https://chem.libretexts.org/Bookshelves/Introductory_Chemistry/Introductory_Chemistry_(LibreTexts)/01%3A_The_Chemical_World/1.E%3A_Exercises")
141
+ ```<end_code>
142
+ *Observation:* The page contains a story about Pasteur and a "horse doctor in eastern France named Louvrier" who claimed to have a cure for anthrax.
143
+
144
+ **Your Turn 3:**
145
+ Thought: I found the answer! The "horse doctor" mentioned is Louvrier. Even though the text says "horse doctor" instead of "equine veterinarian", this is clearly the same profession and the person being asked about.
146
+ Code:
147
+ ```py
148
+ final_answer("Louvrier")
149
+ ```<end_code>
150
+
151
  """
152
 
153
  def generate(
tools.py CHANGED
@@ -1,4 +1,5 @@
1
  import re
 
2
  from typing import Any
3
 
4
  from smolagents import tool, Tool
@@ -37,11 +38,32 @@ class DuckDuckGoSearchTool(Tool):
37
  self.ddgs = DDGS(**kwargs)
38
 
39
  def forward(self, query: str) -> str:
40
- results = self.ddgs.text(query, max_results=self.max_results)
41
- if len(results) == 0:
42
- raise Exception("No results found! Try a less restrictive/shorter query.")
43
- postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
44
- return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  class VisitWebpageTool(Tool):
47
  name = "visit_webpage"
 
1
  import re
2
+ import time
3
  from typing import Any
4
 
5
  from smolagents import tool, Tool
 
38
  self.ddgs = DDGS(**kwargs)
39
 
40
  def forward(self, query: str) -> str:
41
+ max_retries = 3
42
+ retry_delay = 2 # seconds
43
+
44
+ for attempt in range(max_retries):
45
+ try:
46
+ results = self.ddgs.text(query, max_results=self.max_results)
47
+ if len(results) == 0:
48
+ raise Exception("No results found! Try a less restrictive/shorter query.")
49
+ postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
50
+ return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
51
+
52
+ except Exception as e:
53
+ error_msg = str(e)
54
+ if "202" in error_msg or "rate" in error_msg.lower() or "ratelimit" in error_msg.lower():
55
+ if attempt < max_retries - 1:
56
+ print(f"Rate limit hit, retrying in {retry_delay} seconds... (attempt {attempt + 1}/{max_retries})")
57
+ time.sleep(retry_delay)
58
+ retry_delay *= 2 # Exponential backoff
59
+ continue
60
+ else:
61
+ return "## Search Results\n\nRate limit exceeded. Please try again later or use a different search strategy."
62
+ else:
63
+ # For non-rate-limit errors, don't retry
64
+ raise e
65
+
66
+ return "## Search Results\n\nFailed to get search results after multiple attempts."
67
 
68
  class VisitWebpageTool(Tool):
69
  name = "visit_webpage"