Spaces:
Runtime error
Runtime error
File size: 2,488 Bytes
594c559 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import html
import logging
import re
import time
import markdown
import inspect
from camel.messages.system_messages import SystemMessage
from app import send_msg
def now():
return time.strftime("%Y%m%d%H%M%S", time.localtime())
def log_and_print_online(role, content=None):
if not content:
logging.info(role + "\n")
send_msg("System", role)
print(role + "\n")
else:
print(str(role) + ": " + str(content) + "\n")
logging.info(str(role) + ": " + str(content) + "\n")
if isinstance(content, SystemMessage):
records_kv = []
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", " ")
records_kv.append([key, value])
content = "**[SystemMessage**]\n\n" + convert_to_markdown_table(records_kv)
else:
role = str(role)
content = str(content)
send_msg(role, content)
def convert_to_markdown_table(records_kv):
# Create the Markdown table header
header = "| Parameter | Value |\n| --- | --- |"
# Create the Markdown table rows
rows = [f"| **{key}** | {value} |" for (key, value) in records_kv]
# Combine the header and rows to form the final Markdown table
markdown_table = header + "\n" + '\n'.join(rows)
return markdown_table
def log_arguments(func):
def wrapper(*args, **kwargs):
sig = inspect.signature(func)
params = sig.parameters
all_args = {}
all_args.update({name: value for name, value in zip(params.keys(), args)})
all_args.update(kwargs)
records_kv = []
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", " ")
records_kv.append([name, value])
records = f"**[{func.__name__}]**\n\n" + convert_to_markdown_table(records_kv)
log_and_print_online("System", records)
return func(*args, **kwargs)
return wrapper
|