mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2026-05-28 11:23:59 +00:00
feat: Refactored chatdev/utils.py
This commit is contained in:
parent
d1c72940cb
commit
58be398e69
@ -26,11 +26,7 @@ def log_and_print_online(role, content=None):
|
|||||||
content.meta_dict["content"] = content.content
|
content.meta_dict["content"] = content.content
|
||||||
for key in content.meta_dict:
|
for key in content.meta_dict:
|
||||||
value = content.meta_dict[key]
|
value = content.meta_dict[key]
|
||||||
value = str(value)
|
value = escape_string(value)
|
||||||
value = html.unescape(value)
|
|
||||||
value = markdown.markdown(value)
|
|
||||||
value = re.sub(r'<[^>]*>', '', value)
|
|
||||||
value = value.replace("\n", " ")
|
|
||||||
records_kv.append([key, value])
|
records_kv.append([key, value])
|
||||||
content = "**[SystemMessage**]\n\n" + convert_to_markdown_table(records_kv)
|
content = "**[SystemMessage**]\n\n" + convert_to_markdown_table(records_kv)
|
||||||
else:
|
else:
|
||||||
@ -65,11 +61,7 @@ def log_arguments(func):
|
|||||||
for name, value in all_args.items():
|
for name, value in all_args.items():
|
||||||
if name in ["self", "chat_env", "task_type"]:
|
if name in ["self", "chat_env", "task_type"]:
|
||||||
continue
|
continue
|
||||||
value = str(value)
|
value = escape_string(value)
|
||||||
value = html.unescape(value)
|
|
||||||
value = markdown.markdown(value)
|
|
||||||
value = re.sub(r'<[^>]*>', '', value)
|
|
||||||
value = value.replace("\n", " ")
|
|
||||||
records_kv.append([name, value])
|
records_kv.append([name, value])
|
||||||
records = f"**[{func.__name__}]**\n\n" + convert_to_markdown_table(records_kv)
|
records = f"**[{func.__name__}]**\n\n" + convert_to_markdown_table(records_kv)
|
||||||
log_and_print_online("System", records)
|
log_and_print_online("System", records)
|
||||||
@ -77,3 +69,11 @@ def log_arguments(func):
|
|||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user