🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
ignore warning info
lidanyanga2f809263a42
diff --git a/metagpt/actions/di/execute_nb_code.py b/metagpt/actions/di/execute_nb_code.pyindex 64620d9cc..9a9f0483a 100644--- a/metagpt/actions/di/execute_nb_code.py+++ b/metagpt/actions/di/execute_nb_code.py@@ -30,6 +30,12 @@ from metagpt.logs import loggerfrom metagpt.utils.report import NotebookReporterINSTALL_KEEPLEN = 500+INI_CODE = """import warnings+import logging++root_logger = logging.getLogger()+root_logger.setLevel(logging.ERROR)+warnings.filterwarnings('ignore')"""class RealtimeOutputNotebookClient(NotebookClient):@@ -79,6 +85,10 @@ class ExecuteNbCode(Action):)self.reporter = NotebookReporter()self.set_nb_client()+ asyncio.run(self._init_code())++ async def _init_code(self):+ await self.run(INI_CODE)def set_nb_client(self):self.nb_client = RealtimeOutputNotebookClient(@@ -175,6 +185,8 @@ class ExecuteNbCode(Action):is_success = Falseoutput_text = remove_escape_and_color_codes(output_text)+ if is_success:+ output_text = remove_log_and_warning_lines(output_text)# The useful information of the exception is at the end,# the useful information of normal output is at the begining.output_text = output_text[:keep_len] if is_success else output_text[-keep_len:]@@ -268,6 +280,18 @@ class ExecuteNbCode(Action):return outputs, success+def remove_log_and_warning_lines(input_str: str) -> str:+ delete_lines = ["[warning]", "warning:", "[cv]", "[info]"]+ result = "\n".join(+ [+ line+ for line in input_str.split("\n")+ if not any(dl in line.lower() for dl in delete_lines)+ ]+ ).strip()+ return result++def remove_escape_and_color_codes(input_str: str):# 使用正则表达式去除jupyter notebook输出结果中的转义字符和颜色代码# Use regular expressions to get rid of escape characters and color codes in jupyter notebook output.