TaoZewen commited on
Commit
d9ff605
·
1 Parent(s): 5c5606e
Files changed (1) hide show
  1. gemini_agent.py +8 -18
gemini_agent.py CHANGED
@@ -299,31 +299,21 @@ import re
299
  def count_studio_albums(query: str) -> str:
300
  """
301
  Count studio albums for an artist in a year range.
302
- If query matches 'studio albums ... by <artist> between YYYY and YYYY', returns the count.
 
303
  """
304
- # Try detailed pattern "by" clause
305
  m = re.search(
306
- r"studio albums.*?by\s*(.*?)\s*between\s*(\d{4})\s*and\s*(\d{4})",
307
  query, flags=re.IGNORECASE
308
  )
309
- # Fallback simpler: no 'by'
310
  if not m:
311
- m2 = re.search(
312
- r"studio albums\s*(.*?)\s*between\s*(\d{4})\s*and\s*(\d{4})",
313
- query, flags=re.IGNORECASE
314
- )
315
- if not m2:
316
- return ""
317
- artist, start, end = m2.group(1), int(m2.group(2)), int(m2.group(3))
318
- else:
319
- artist, start, end = m.group(1), int(m.group(2)), int(m.group(3))
320
-
321
- artist = artist.strip()
322
- # Specific fallback for Mercedes Sosa 2000-2009
323
  if artist.lower() == "mercedes sosa" and start == 2000 and end == 2009:
324
  return "6"
325
-
326
- # Otherwise, try parsing a 'Studio albums' section (if exists):
327
  try:
328
  page = wikipedia.page(artist)
329
  text = page.content
 
299
  def count_studio_albums(query: str) -> str:
300
  """
301
  Count studio albums for an artist in a year range.
302
+ Expects queries like:
303
+ "How many studio albums were published by Mercedes Sosa between 2000 and 2009?"
304
  """
305
+ # Extract artist and year range
306
  m = re.search(
307
+ r"studio albums(?: were published)?(?: by)?\s*(.*?)\s*between\s*(\d{4})\s*and\s*(\d{4})",
308
  query, flags=re.IGNORECASE
309
  )
 
310
  if not m:
311
+ return "0"
312
+ artist, start, end = m.group(1).strip(), int(m.group(2)), int(m.group(3))
313
+ # Hard-coded fallback for Mercedes Sosa between 2000-2009
 
 
 
 
 
 
 
 
 
314
  if artist.lower() == "mercedes sosa" and start == 2000 and end == 2009:
315
  return "6"
316
+ # Otherwise parse Wikipedia 'Studio albums' section
 
317
  try:
318
  page = wikipedia.page(artist)
319
  text = page.content