mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
ignore warning info
This commit is contained in:
parent
4dfe8524a1
commit
a2f809263a
1 changed files with 24 additions and 0 deletions
|
|
@ -30,6 +30,12 @@ from metagpt.logs import logger
|
|||
from metagpt.utils.report import NotebookReporter
|
||||
|
||||
INSTALL_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 = False
|
||||
|
||||
output_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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue