MathFrenchToast's picture
refactor: code organisation + info about local services on the gradio home page
bbc85bc
import time
def save_file_with_timestamp(content: str, file_name: str, extension: str) -> str:
"""
Save content to a file with a timestamp.
Args:
content (str): The content to save.
file_name (str): The base name of the file.
Returns:
str: The path to the saved file.
"""
try:
# save content to a file in test folder before returning
# compute filepath with correct extension based on convert_to_markdown and add a timestamp for unicity
unicity_suffix = str(int(time.time()))
file_path = f"test/{file_name}_{unicity_suffix}.{extension}"
with open(file_name, "w", encoding="utf-8") as f:
f.write(content)
except Exception as e:
print(f"Error saving content to file: {e}")
return file_name
def mylog(agent_name: str, message: str, depth: int = 0) -> None:
"""
Log a message with indentation based on the depth.
Args:
agent_name (str): The name of the agent.
message (str): The message to log.
depth (int): The depth of the log message.
"""
indent = " " * (depth * 4)
try:
# log agent call in file
with open("logs/agent_calls.log", "a") as log_file:
log_file.write(f"{indent}{agent_name}: {message}\n")
except Exception as e:
print(f"Error logging agent call: {e}")