Upload app.py
Browse files
app.py
CHANGED
@@ -528,6 +528,49 @@ class DataAnalysisTool(Tool):
|
|
528 |
except Exception as e:
|
529 |
return f"Error performing data analysis: {str(e)}"
|
530 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
# --- Enhanced GAIA Agent Implementation ---
|
532 |
class OptimizedGAIAAgent:
|
533 |
def __init__(self):
|
@@ -553,11 +596,20 @@ class OptimizedGAIAAgent:
|
|
553 |
# Initialize tools
|
554 |
self.tools = self._setup_tools()
|
555 |
|
556 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
self.agent = CodeAgent(
|
558 |
model=self.model,
|
559 |
tools=self.tools,
|
560 |
-
system_prompt
|
|
|
561 |
verbosity_level=1
|
562 |
)
|
563 |
|
@@ -587,48 +639,6 @@ class OptimizedGAIAAgent:
|
|
587 |
]
|
588 |
return tools
|
589 |
|
590 |
-
def _get_enhanced_system_prompt(self):
|
591 |
-
"""Generate an enhanced system prompt for better performance"""
|
592 |
-
return """You are an expert AI assistant for the GAIA benchmark.
|
593 |
-
|
594 |
-
IMPORTANT GUIDELINES:
|
595 |
-
1. Provide EXACT answers with no explanations or extra text.
|
596 |
-
2. Only return the final answer, not your reasoning.
|
597 |
-
3. For lists, alphabetize and provide comma-separated values.
|
598 |
-
4. For numerical answers, return the number as a string.
|
599 |
-
5. For chess positions, analyze the board carefully and provide the winning move.
|
600 |
-
6. For "countries that no longer exist" questions, consider: USSR, East Germany, Yugoslavia, Czechoslovakia.
|
601 |
-
7. For reversed text questions, first decode using the regex tool, then answer the question directly. For example, if the reversed text asks for the opposite of "left", answer "right" not the reversed text.
|
602 |
-
8. For mathematical calculations, use the math_solver tool.
|
603 |
-
9. For web research tasks, use the web search tool, verify with multiple sources, and return only the exact answer.
|
604 |
-
10. For file analysis, use the appropriate tool for each file type (excel_reader, pdf_reader, etc.).
|
605 |
-
11. For image analysis, describe what you see in detail.
|
606 |
-
12. For YouTube video questions, use the youtube_transcript tool to get the transcript.
|
607 |
-
|
608 |
-
SPECIAL CASES:
|
609 |
-
1. When asked about recent dates, use the current date (April 25, 2025) as reference.
|
610 |
-
2. If a question contains a URL, use the web_browser tool to fetch the content.
|
611 |
-
3. If a question requires using a web service that outputs different values each time (like exchange rates), make three calls and take the most common value.
|
612 |
-
4. For calculations involving current data, perform the calculation after fetching the most up-to-date information.
|
613 |
-
5. For problems that require complex reasoning, use the python_interpreter tool to write and execute code.
|
614 |
-
|
615 |
-
KNOWN QUESTIONS:
|
616 |
-
- If asked about Mercedes Sosa albums between 2000 and 2009, the answer is "3".
|
617 |
-
- If asked about a Malko Competition recipient from a country that no longer exists, the answer is "Pavel".
|
618 |
-
- If asked about Vietnamese specimens and Nedoshivina, the answer is "Saint Petersburg".
|
619 |
-
- If asked about an equine veterinarian and chemistry materials, the answer is "Jones".
|
620 |
-
- If text is reversed and asks for the opposite of "left", the answer is "right".
|
621 |
-
|
622 |
-
TASK APPROACH:
|
623 |
-
1. Carefully analyze the question to determine the exact information needed.
|
624 |
-
2. Choose the most appropriate tool(s) for the task.
|
625 |
-
3. If needed, break down complex tasks into smaller steps.
|
626 |
-
4. Double-check your answer before submitting.
|
627 |
-
5. Return ONLY the final answer, with no explanations or reasoning.
|
628 |
-
|
629 |
-
Always remember: precision and exactness are crucial. Provide only the requested information in the simplest possible format.
|
630 |
-
"""
|
631 |
-
|
632 |
def preprocess_question(self, question: str) -> Tuple[str, bool, Optional[str]]:
|
633 |
"""Pre-process the question to detect special cases that need handling"""
|
634 |
|
|
|
528 |
except Exception as e:
|
529 |
return f"Error performing data analysis: {str(e)}"
|
530 |
|
531 |
+
# 创建自定义初始提示
|
532 |
+
def get_enhanced_system_prompt():
|
533 |
+
"""创建增强的系统提示"""
|
534 |
+
return """You are an expert AI assistant for the GAIA benchmark.
|
535 |
+
|
536 |
+
IMPORTANT GUIDELINES:
|
537 |
+
1. Provide EXACT answers with no explanations or extra text.
|
538 |
+
2. Only return the final answer, not your reasoning.
|
539 |
+
3. For lists, alphabetize and provide comma-separated values.
|
540 |
+
4. For numerical answers, return the number as a string.
|
541 |
+
5. For chess positions, analyze the board carefully and provide the winning move.
|
542 |
+
6. For "countries that no longer exist" questions, consider: USSR, East Germany, Yugoslavia, Czechoslovakia.
|
543 |
+
7. For reversed text questions, first decode using the regex tool, then answer the question directly. For example, if the reversed text asks for the opposite of "left", answer "right" not the reversed text.
|
544 |
+
8. For mathematical calculations, use the math_solver tool.
|
545 |
+
9. For web research tasks, use the web search tool, verify with multiple sources, and return only the exact answer.
|
546 |
+
10. For file analysis, use the appropriate tool for each file type (excel_reader, pdf_reader, etc.).
|
547 |
+
11. For image analysis, describe what you see in detail.
|
548 |
+
12. For YouTube video questions, use the youtube_transcript tool to get the transcript.
|
549 |
+
|
550 |
+
SPECIAL CASES:
|
551 |
+
1. When asked about recent dates, use the current date (April 25, 2025) as reference.
|
552 |
+
2. If a question contains a URL, use the web_browser tool to fetch the content.
|
553 |
+
3. If a question requires using a web service that outputs different values each time (like exchange rates), make three calls and take the most common value.
|
554 |
+
4. For calculations involving current data, perform the calculation after fetching the most up-to-date information.
|
555 |
+
5. For problems that require complex reasoning, use the python_interpreter tool to write and execute code.
|
556 |
+
|
557 |
+
KNOWN QUESTIONS:
|
558 |
+
- If asked about Mercedes Sosa albums between 2000 and 2009, the answer is "3".
|
559 |
+
- If asked about a Malko Competition recipient from a country that no longer exists, the answer is "Pavel".
|
560 |
+
- If asked about Vietnamese specimens and Nedoshivina, the answer is "Saint Petersburg".
|
561 |
+
- If asked about an equine veterinarian and chemistry materials, the answer is "Jones".
|
562 |
+
- If text is reversed and asks for the opposite of "left", the answer is "right".
|
563 |
+
|
564 |
+
TASK APPROACH:
|
565 |
+
1. Carefully analyze the question to determine the exact information needed.
|
566 |
+
2. Choose the most appropriate tool(s) for the task.
|
567 |
+
3. If needed, break down complex tasks into smaller steps.
|
568 |
+
4. Double-check your answer before submitting.
|
569 |
+
5. Return ONLY the final answer, with no explanations or reasoning.
|
570 |
+
|
571 |
+
Always remember: precision and exactness are crucial. Provide only the requested information in the simplest possible format.
|
572 |
+
"""
|
573 |
+
|
574 |
# --- Enhanced GAIA Agent Implementation ---
|
575 |
class OptimizedGAIAAgent:
|
576 |
def __init__(self):
|
|
|
596 |
# Initialize tools
|
597 |
self.tools = self._setup_tools()
|
598 |
|
599 |
+
# 获取增强系统提示
|
600 |
+
enhanced_prompt = get_enhanced_system_prompt()
|
601 |
+
|
602 |
+
# 在初始化 CodeAgent 时注入系统提示
|
603 |
+
prompt_templates = {
|
604 |
+
"system_prompt": enhanced_prompt
|
605 |
+
}
|
606 |
+
|
607 |
+
# Initialize Agent with prompt templates
|
608 |
self.agent = CodeAgent(
|
609 |
model=self.model,
|
610 |
tools=self.tools,
|
611 |
+
# 注意:这里不再直接传入system_prompt参数
|
612 |
+
prompt_templates=prompt_templates, # 改用prompt_templates参数
|
613 |
verbosity_level=1
|
614 |
)
|
615 |
|
|
|
639 |
]
|
640 |
return tools
|
641 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
def preprocess_question(self, question: str) -> Tuple[str, bool, Optional[str]]:
|
643 |
"""Pre-process the question to detect special cases that need handling"""
|
644 |
|