Merge branch 'feat/data_visualization_hackathon' into feat/data_visualization_hackathon_zzx
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import sys
|
||||
from io import StringIO
|
||||
|
||||
from app.tool.chart_visualization.utils import extract_executable_code
|
||||
from app.tool.python_execute import PythonExecute
|
||||
|
||||
|
||||
@@ -132,19 +128,5 @@ class NormalPythonExecute(PythonExecute):
|
||||
"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)
|
||||
|
||||
Reference in New Issue
Block a user