feat: update data analysis agent prompt and output content

This commit is contained in:
ZJU_czx
2025-03-31 17:34:33 +08:00
parent 722d5c787d
commit d3313a6b39
9 changed files with 176 additions and 120 deletions
@@ -1,10 +1,4 @@
import sys
from io import StringIO
from app.tool.python_execute import PythonExecute
from app.tool.chart_visualization.utils import (
extract_executable_code,
)
class NormalPythonExecute(PythonExecute):
@@ -12,35 +6,27 @@ class NormalPythonExecute(PythonExecute):
name: str = "common_python_execute"
description: str = (
"""Executes Python code strings to do data analysis. Note:
1. Only outputs from print() are visible; function return values are not captured. Use print() statements to display results
2. Do data analysis (cleaning / transform) saved in *.csv
3. Generate a data analysis report in *.md"""
"""Executes Python code strings to tasks such as data process and data report"""
)
parameters: dict = {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "The Python code to execute.",
"description": """The Python code to execute. Note:
1. Only outputs from print() are visible; function return values are not captured. Use print() statements to display results
2. Do data process (cleaning / transform) saved in *.csv
3. Generate a data analysis report in html""",
},
"code_type": {
"description": "code type",
"type": "string",
"default": "html",
"enum": ["process", "report", "others"],
},
},
"required": ["code"],
}
def _run_code(self, code: str, result_dict: dict, safe_globals: dict) -> None:
original_stdout = sys.stdout
be_extracted_code = extract_executable_code(code) # ignore_security_alert RCE
try:
output_buffer = StringIO()
sys.stdout = output_buffer
exec( # ignore_security_alert RCE
be_extracted_code, safe_globals, safe_globals
) # ignore_security_alert RCE
result_dict["observation"] = output_buffer.getvalue()
result_dict["success"] = True
except Exception as e:
result_dict["observation"] = str(e)
result_dict["success"] = False
finally:
sys.stdout = original_stdout
async def execute(self, code: str, code_type: str, timeout=5):
return await super().execute(code, timeout)