Kackle commited on
Commit
5604ed9
·
verified ·
1 Parent(s): 907dcf7

slight change

Browse files
Files changed (1) hide show
  1. app.py +44 -39
app.py CHANGED
@@ -59,10 +59,10 @@ class GoogleSearchTool(Tool):
59
  'key': self.google_search_api_key,
60
  'cx': self.google_search_cx,
61
  'q': query,
62
- 'num': 5
63
  }
64
 
65
- response = requests.get(url, params=params, timeout=10)
66
  if response.status_code != 200:
67
  return f"Google Search failed with status {response.status_code}"
68
 
@@ -70,14 +70,15 @@ class GoogleSearchTool(Tool):
70
  if 'items' not in results:
71
  return f"No search results found for: {query}"
72
 
73
- # Format search results
74
- formatted_results = f"Google search results for '{query}':\n\n"
75
- for item in results['items']:
76
  title = item.get('title', 'No title')
77
  snippet = item.get('snippet', 'No description')
78
- formatted_results += f"• {title}: {snippet}\n"
 
79
 
80
- return formatted_results[:1000] # Limit length
81
 
82
  except Exception as e:
83
  return f"Google Search error for '{query}': {str(e)}"
@@ -417,38 +418,34 @@ class SlpMultiAgent:
417
  lambda: manager_agent.run(f"""
418
  Question: {short_question}
419
 
420
- CRITICAL INSTRUCTIONS:
421
- 1. Use tools DIRECTLY, not in code execution
422
- 2. For factual questions: Use google_search() tool immediately
423
- 3. For math: Use math_calculator() tool directly
424
- 4. DO NOT write complex code - use tools instead
425
- 5. DO NOT call ResearchAgent() or SolverAgent() in code
426
 
427
- Available tools:
428
- - google_search(query): Search the web
429
- - math_calculator(expression): Calculate math
430
- - file_processor(action, data): Handle files
431
- - knowledge_base(topic): Get knowledge
 
432
 
433
- SIMPLE APPROACH:
434
- - Call the appropriate tool
435
- - Get the result
436
- - Provide final_answer()
437
 
438
- Example for factual question:
439
- 1. Call google_search("your query")
440
- 2. Extract answer from results
441
- 3. Call final_answer("the answer")
442
 
443
- NO complex code execution. Use tools directly.
444
 
445
- Take your time and think every step out, be confident and precise.
446
-
447
- Google should be able to answer all these questions and you have access to it.
448
-
449
- They are simple yet tricky questions, so be careful and double check your answers. Make sure to use google_search for any factual question.
450
-
451
- always provide a final_answer in the format final_answer("your answer here") when you have the answer.
 
452
  """)
453
  )
454
  break # Success, exit retry loop
@@ -472,12 +469,20 @@ class SlpMultiAgent:
472
 
473
  # Extract clean answer from result
474
  if result and isinstance(result, str):
475
- # Look for final_answer pattern
476
  import re
477
- final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\'\)]', result) # Fixed regex
478
- if final_answer_match:
479
- clean_answer = final_answer_match.group(1)
480
- return clean_answer
 
 
 
 
 
 
 
 
481
 
482
  # If no final_answer found, try to extract the last meaningful line
483
  lines = result.strip().split('\n')
 
59
  'key': self.google_search_api_key,
60
  'cx': self.google_search_cx,
61
  'q': query,
62
+ 'num': 8 # Increased for better coverage
63
  }
64
 
65
+ response = requests.get(url, params=params, timeout=15)
66
  if response.status_code != 200:
67
  return f"Google Search failed with status {response.status_code}"
68
 
 
70
  if 'items' not in results:
71
  return f"No search results found for: {query}"
72
 
73
+ # Format search results with more detail
74
+ formatted_results = f"Search results for '{query}':\n\n"
75
+ for i, item in enumerate(results['items'], 1):
76
  title = item.get('title', 'No title')
77
  snippet = item.get('snippet', 'No description')
78
+ link = item.get('link', '')
79
+ formatted_results += f"{i}. {title}\n {snippet}\n Source: {link}\n\n"
80
 
81
+ return formatted_results[:2000] # Increased limit
82
 
83
  except Exception as e:
84
  return f"Google Search error for '{query}': {str(e)}"
 
418
  lambda: manager_agent.run(f"""
419
  Question: {short_question}
420
 
421
+ CRITICAL: Read the question CAREFULLY and answer EXACTLY what is asked.
 
 
 
 
 
422
 
423
+ STEP-BY-STEP APPROACH:
424
+ 1. ANALYZE: What type of question is this?
425
+ - Factual/Historical: Use google_search
426
+ - Math/Calculation: Use math_calculator
427
+ - List/Categorization: Use google_search for verification
428
+ - File analysis: Use file_processor
429
 
430
+ 2. SEARCH: Use the appropriate tool with SPECIFIC queries
431
+ - For Olympics: "1928 Summer Olympics countries athletes least"
432
+ - For vegetables: "botanical vegetables vs fruits classification"
433
+ - For specific people: "[person name] [context] [year]"
434
 
435
+ 3. EXTRACT: Get the EXACT answer from results
436
+ - Look for specific numbers, names, codes
437
+ - Pay attention to format requirements (IOC codes, last names only, etc.)
 
438
 
439
+ 4. VERIFY: Double-check your answer matches the question format
440
 
441
+ 5. ANSWER: Use final_answer("exact answer here")
442
+
443
+ EXAMPLES:
444
+ - Country question → Search → Find IOC code → final_answer("IOC")
445
+ - Vegetable list Search botanical classification List vegetables final_answer("item1, item2, item3")
446
+ - Person question → Search specific details �� Extract names → final_answer("Name1, Name2")
447
+
448
+ REMEMBER: Answer format matters! Follow instructions exactly.
449
  """)
450
  )
451
  break # Success, exit retry loop
 
469
 
470
  # Extract clean answer from result
471
  if result and isinstance(result, str):
472
+ # Look for final_answer pattern with multiple formats
473
  import re
474
+ patterns = [
475
+ r'final_answer\(["\']([^"\']*)["\'\)]',
476
+ r'final_answer\(([^)]+)\)',
477
+ r'Final answer: ([^\n]+)',
478
+ r'Answer: ([^\n]+)'
479
+ ]
480
+
481
+ for pattern in patterns:
482
+ match = re.search(pattern, result, re.IGNORECASE)
483
+ if match:
484
+ clean_answer = match.group(1).strip('"\'')
485
+ return clean_answer
486
 
487
  # If no final_answer found, try to extract the last meaningful line
488
  lines = result.strip().split('\n')