Spaces:
Sleeping
Sleeping
slight change
Browse files
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':
|
| 63 |
}
|
| 64 |
|
| 65 |
-
response = requests.get(url, params=params, timeout=
|
| 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"
|
| 75 |
-
for item in results['items']:
|
| 76 |
title = item.get('title', 'No title')
|
| 77 |
snippet = item.get('snippet', 'No description')
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
return formatted_results[:
|
| 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
|
| 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 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
|
|
|
| 432 |
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
3. Call final_answer("the answer")
|
| 442 |
|
| 443 |
-
|
| 444 |
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
| 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 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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')
|