File size: 1,460 Bytes
5675d05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")