mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-14 15:25:17 +02:00
fix: remove escape and color codes for output of nbclient.
This commit is contained in:
parent
b28111ab34
commit
8aa096a334
1 changed files with 10 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import json
|
|||
import subprocess
|
||||
|
||||
import fire
|
||||
import re
|
||||
|
||||
from metagpt.roles import Role
|
||||
from metagpt.actions import Action
|
||||
|
|
@ -35,6 +36,13 @@ def truncate(result: str, keep_len: int = 1000) -> str:
|
|||
return desc
|
||||
|
||||
|
||||
def remove_escape_and_color_codes(input_str):
|
||||
# 使用正则表达式去除转义字符和颜色代码
|
||||
pattern = re.compile(r'\x1b\[[0-9;]*[mK]')
|
||||
result = pattern.sub('', input_str)
|
||||
return result
|
||||
|
||||
|
||||
class AskReview(Action):
|
||||
async def run(self, context: List[Message], plan: Plan = None):
|
||||
logger.info("Current overall plan:")
|
||||
|
|
@ -137,8 +145,9 @@ class MLEngineer(Role):
|
|||
# truncated the result
|
||||
print(truncate(result))
|
||||
# print(result)
|
||||
_result = truncate(remove_escape_and_color_codes(result))
|
||||
self.working_memory.add(
|
||||
Message(content=result, role="user", cause_by=ExecutePyCode)
|
||||
Message(content=_result, role="user", cause_by=ExecutePyCode)
|
||||
)
|
||||
|
||||
if "!pip" in code:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue