From 58be398e69fd58c08d563075e23f60237f13b897 Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:10:35 +0000 Subject: [PATCH] feat: Refactored chatdev/utils.py --- chatdev/utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/chatdev/utils.py b/chatdev/utils.py index 80b4ff1a..0757b189 100644 --- a/chatdev/utils.py +++ b/chatdev/utils.py @@ -26,11 +26,7 @@ def log_and_print_online(role, content=None): content.meta_dict["content"] = content.content for key in content.meta_dict: value = content.meta_dict[key] - value = str(value) - value = html.unescape(value) - value = markdown.markdown(value) - value = re.sub(r'<[^>]*>', '', value) - value = value.replace("\n", " ") + value = escape_string(value) records_kv.append([key, value]) content = "**[SystemMessage**]\n\n" + convert_to_markdown_table(records_kv) else: @@ -65,11 +61,7 @@ def log_arguments(func): for name, value in all_args.items(): if name in ["self", "chat_env", "task_type"]: continue - value = str(value) - value = html.unescape(value) - value = markdown.markdown(value) - value = re.sub(r'<[^>]*>', '', value) - value = value.replace("\n", " ") + value = escape_string(value) records_kv.append([name, value]) records = f"**[{func.__name__}]**\n\n" + convert_to_markdown_table(records_kv) log_and_print_online("System", records) @@ -77,3 +69,11 @@ def log_arguments(func): return func(*args, **kwargs) return wrapper + +def escape_string(value): + value = str(value) + value = html.unescape(value) + value = markdown.markdown(value) + value = re.sub(r'<[^>]*>', '', value) + value = value.replace("\n", " ") + return value