Andrei Nazarov commited on
Commit
86724c1
·
1 Parent(s): 04eadcc

refactored

Browse files
Files changed (1) hide show
  1. app.py +25 -36
app.py CHANGED
@@ -54,7 +54,14 @@ class GeminiModel(Model):
54
  self.model = genai.GenerativeModel('models/gemini-2.0-flash-lite')
55
  self.rate_limiter = RateLimiter(requests_per_minute=25)
56
 
57
- self.system_prompt = """You are a high-performance reasoning agent. Your goal is to answer questions by breaking them down into a series of logical steps using the tools provided.
 
 
 
 
 
 
 
58
 
59
  **YOUR TOOLS**
60
  - `web_search(query: str)`: Finds URLs and information.
@@ -66,61 +73,43 @@ class GeminiModel(Model):
66
  1. **Think (`Thought:`):** Analyze the question and create a plan.
67
  2. **Act (`Code:`):** Execute ONE step of your plan.
68
  3. **Observe (`Observation:`):** Use the result to inform your next step.
69
- 4. **Repeat** until you have the final answer.
70
  5. **Submit** your answer using `final_answer()`.
71
 
72
  ---
73
- **EXAMPLE 1: Using `web_search` and `visit_webpage`**
74
- *Question:* What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?
 
75
 
76
  **Your Turn 1:**
77
- Thought: I need to find the specific LibreText page. I'll use `web_search`.
78
  Code:
79
  ```py
80
- web_search(query="LibreTexts Introductory Chemistry Agnew 1.E Exercises")
81
  ```<end_code>
82
- *Observation:* A search result shows the URL `https://chem.libretexts.org/.../1.E%3A_Exercises`.
83
 
84
  **Your Turn 2:**
85
- Thought: I have the URL. Now I need to read the content of the page to find the name.
86
  Code:
87
  ```py
88
- visit_webpage(url="https://chem.libretexts.org/Courses/Some_College/Introductory_Chemistry_(Alviar-Agnew_and_Agnew)/01%3A_Introduction_to_Chemistry/1.E%3A_Exercises")
89
  ```<end_code>
90
- *Observation:* The webpage content includes the text "...an equine veterinarian, Dr. Smith...".
91
 
92
  **Your Turn 3:**
93
- Thought: I've found the surname. It's Smith.
94
  Code:
95
  ```py
96
- final_answer("Smith")
97
  ```<end_code>
 
98
 
99
- ---
100
- **EXAMPLE 2: Finding a specific count**
101
- *Question:* How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)?
102
-
103
- **Your Turn 1:**
104
- Thought: I need to find a reliable discography for Mercedes Sosa. `wikipedia_search` is a good starting point.
105
- Code:
106
- ```py
107
- wikipedia_search(query="Mercedes Sosa discography")
108
- ```<end_code>
109
- *Observation:* The Wikipedia summary lists several albums.
110
-
111
- **Your Turn 2:**
112
- Thought: The summary is a good start, but I need a more detailed list with years to be sure. I will visit the Wikipedia page itself to get the full discography. The search result from the previous step implicitly gives me the URL.
113
- Code:
114
- ```py
115
- visit_webpage(url="https://en.wikipedia.org/wiki/Mercedes_Sosa_discography")
116
- ```<end_code>
117
- *Observation:* The page content contains a "Studio albums" section with dates. I can read it and count: *Acústico* (2002), *Corazón libre* (2005), *Cantora 1* (2009), *Cantora 2* (2009).
118
-
119
- **Your Turn 3:**
120
- Thought: I have counted 4 studio albums in the specified period.
121
  Code:
122
  ```py
123
- final_answer("4")
124
  ```<end_code>
125
  """
126
 
@@ -212,7 +201,7 @@ class MyAgent:
212
  VisitWebpageTool(),
213
  ],
214
  model=self.model,
215
- max_steps=7 # Keep high for multi-step reasoning
216
  )
217
 
218
  def __call__(self, question: str) -> str:
 
54
  self.model = genai.GenerativeModel('models/gemini-2.0-flash-lite')
55
  self.rate_limiter = RateLimiter(requests_per_minute=25)
56
 
57
+ self.system_prompt = """You are a high-performance reasoning agent focused on ACCURACY. Your goal is to answer questions by breaking them down into logical steps and VERIFYING your information from multiple sources.
58
+
59
+ **CRITICAL ACCURACY RULES:**
60
+ - ALWAYS verify information from multiple sources when possible
61
+ - Distinguish between different types of releases (studio albums vs live albums vs compilations)
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.
 
73
  1. **Think (`Thought:`):** Analyze the question and create a plan.
74
  2. **Act (`Code:`):** Execute ONE step of your plan.
75
  3. **Observe (`Observation:`):** Use the result to inform your next step.
76
+ 4. **Verify:** Cross-check information when possible.
77
  5. **Submit** your answer using `final_answer()`.
78
 
79
  ---
80
+
81
+ **EXAMPLE 2: Finding a specific count with verification**
82
+ *Question:* How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)?
83
 
84
  **Your Turn 1:**
85
+ Thought: I need to find a reliable discography for Mercedes Sosa. I'll search for multiple sources to verify the information.
86
  Code:
87
  ```py
88
+ web_search(query="Mercedes Sosa studio albums discography 2000-2009")
89
  ```<end_code>
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).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  Code:
111
  ```py
112
+ final_answer("3")
113
  ```<end_code>
114
  """
115
 
 
201
  VisitWebpageTool(),
202
  ],
203
  model=self.model,
204
+ max_steps=10 # Increased for better verification and accuracy
205
  )
206
 
207
  def __call__(self, question: str) -> str: