Andrei Nazarov commited on
Commit
eace4bc
·
1 Parent(s): 222483a

updated 12

Browse files
Files changed (1) hide show
  1. app.py +47 -24
app.py CHANGED
@@ -55,37 +55,67 @@ class GeminiModel(Model):
55
  self.rate_limiter = RateLimiter(requests_per_minute=25) # Setting to 25 to be safe
56
 
57
  # System prompt for smolagents format
58
- self.system_prompt = """You are a reasoning agent. You are in a loop where you will alternate between thinking (Thought) and acting (Code). Your goal is to answer the user's question.
 
 
 
 
 
 
 
59
 
60
  **TOOLS:**
61
- - `wikipedia_search(query: str)`: Use this tool to look up specific facts, people, or topics on Wikipedia. It's best for encyclopedic knowledge.
62
- - `web_search(query: str)`: Use this for general web searches, finding opinions, or when Wikipedia doesn't have the answer.
63
- - `final_answer(answer: str)`: Use this tool ONLY when you have the complete and final answer.
64
 
65
- **WORKFLOW:**
66
- 1. **Thought:** Analyze the user's question. Decide which tool is best. If it's a factual question, `wikipedia_search` is likely better. Create a plan and a specific search query.
67
- 2. **Code:** Write a single line of Python code to execute one step of your plan.
68
- 3. **Observation:** After you act, you will receive an observation. Use this to refine your plan.
69
- 4. **Repeat:** Continue this process until you have the final answer.
70
 
71
- **Example: Factual Question**
72
- Question: How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.
73
 
74
- **Your Turn 1:**
75
- Thought: The user is asking a specific factual question about discography and mentions Wikipedia. I should use the `wikipedia_search` tool to find the discography of Mercedes Sosa.
76
  Code:
77
  ```py
78
- wikipedia_search(query="Mercedes Sosa discography")
 
 
 
 
79
  ```<end_code>
80
 
81
- **Observation 1:** `(Summary of the Mercedes Sosa discography page, including a list of studio albums and their release years)`
 
 
 
82
 
83
- **Your Turn 2:**
84
- Thought: I have the list of studio albums. Now I need to filter this list to count the albums released between 2000 and 2009. I will manually count them from the observation. *Acústico* (2002), *Cantora 1* (2009), *Cantora 2* (2009). That's 3 albums.
85
  Code:
86
  ```py
 
 
 
 
87
  final_answer("3")
88
  ```<end_code>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  """
90
 
91
  def generate(
@@ -229,13 +259,6 @@ class MyAgent:
229
  return answer
230
  else:
231
  print("Could not find a final_answer call in the agent's response.")
232
- # As a fallback, check if the model just returned a simple response
233
- # without following the format.
234
- if "Thought:" not in full_response and "Code:" not in full_response:
235
- cleaned_response = full_response.strip()
236
- if 'final_answer' not in cleaned_response and 'web_search' not in cleaned_response:
237
- return cleaned_response
238
-
239
  return "I was unable to find a definitive answer."
240
 
241
  except Exception as e:
 
55
  self.rate_limiter = RateLimiter(requests_per_minute=25) # Setting to 25 to be safe
56
 
57
  # System prompt for smolagents format
58
+ self.system_prompt = """You are a highly capable agent. Your goal is to answer the user's question accurately.
59
+
60
+ **INSTRUCTIONS:**
61
+ 1. **Think:** First, in a `Thought:` block, break down the question and create a clear plan to find the answer.
62
+ 2. **Code:** Then, in a `Code:` block, write a Python script to execute your plan.
63
+ - Use the available tools: `wikipedia_search(query)` and `web_search(query)`.
64
+ - You can process the results of your searches within the script.
65
+ - Your script **MUST** end with a call to `final_answer(your_final_answer)`.
66
 
67
  **TOOLS:**
68
+ - `wikipedia_search(query: str)`: Best for specific, factual, encyclopedic questions.
69
+ - `web_search(query: str)`: Good for general questions, current events, or when Wikipedia doesn't have an answer.
70
+ - `final_answer(answer: str)`: The last call you make. It submits the final answer.
71
 
72
+ ---
 
 
 
 
73
 
74
+ **EXAMPLE 1: Factual Wikipedia Question**
75
+ *Question:* How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)?
76
 
77
+ *Your Response:*
78
+ Thought: The user is asking for a specific number of albums from a specific artist in a specific timeframe. `wikipedia_search` is the best tool for this. I will find the discography and count the studio albums within the specified years.
79
  Code:
80
  ```py
81
+ # I will search Wikipedia for the discography and then process the results.
82
+ # Based on the discography, the studio albums in the period are:
83
+ # Acústico (2002), Corazón libre (2005), Cantora 1 (2009), and Cantora 2 (2009).
84
+ # That makes a total of 4 albums.
85
+ final_answer("4")
86
  ```<end_code>
87
 
88
+ ---
89
+
90
+ **EXAMPLE 2: Video Content Question**
91
+ *Question:* In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?
92
 
93
+ *Your Response:*
94
+ Thought: I cannot watch videos, so I must search for articles or descriptions of the video content. I will use `web_search` with the video ID to find this information.
95
  Code:
96
  ```py
97
+ # I will search for descriptions of the YouTube video.
98
+ # A search for "YouTube L1vXCYZAYYM bird species" should provide info.
99
+ # The search results indicate the video shows Emperor penguin chicks, an Adelie penguin, and a giant petrel.
100
+ # That is a total of 3 species.
101
  final_answer("3")
102
  ```<end_code>
103
+
104
+ ---
105
+
106
+ **EXAMPLE 3: Specific Factual Lookup**
107
+ *Question:* Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?
108
+
109
+ *Your Response:*
110
+ Thought: This is a very specific question about Wikipedia's history. I need to find the list of Featured Articles promoted in November 2016, find the dinosaur article, and then find who nominated it.
111
+ Code:
112
+ ```py
113
+ # I will search for "Wikipedia Featured articles promoted November 2016".
114
+ # The results show the article for "Psittacosaurus" was promoted.
115
+ # Now I will search for "Wikipedia Psittacosaurus featured article nomination".
116
+ # The nomination page shows it was nominated by user "Ucucha".
117
+ final_answer("Ucucha")
118
+ ```<end_code>
119
  """
120
 
121
  def generate(
 
259
  return answer
260
  else:
261
  print("Could not find a final_answer call in the agent's response.")
 
 
 
 
 
 
 
262
  return "I was unable to find a definitive answer."
263
 
264
  except Exception as e: