File size: 3,175 Bytes
4d969ce
 
 
8069b5d
4d969ce
ed306c8
6141f1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1923ab6
722929d
ed306c8
4d969ce
 
 
ed306c8
7ddfa83
4d969ce
 
 
 
d8a9c24
eda68a5
 
ed306c8
7ddfa83
4d969ce
 
722929d
4d969ce
722929d
 
d56f6b1
4d969ce
d56f6b1
4d969ce
7ddfa83
05c2b03
 
 
 
 
b1c069d
 
6a92de3
 
 
b1c069d
7ddfa83
05c2b03
567c79d
05c2b03
f0ef4a9
6141f1b
 
6a92de3
6141f1b
 
 
6a92de3
6141f1b
 
 
 
 
 
 
 
4e847ac
6141f1b
 
 
2897070
6141f1b
 
 
2897070
6141f1b
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from autogen import ConversableAgent, AssistantAgent
from autogen.coding import LocalCommandLineCodeExecutor

import base64, markdown, os
#from IPython.display import Image

def read_image_file(image_file_path: str) -> str:
    """
    Read a PNG image file from the local filesystem and encode it as a base64 string.

    Args:
        image_file_path (str): The local file path of the image.

    Returns:
        str: The base64-encoded image data.
    """
    with open(image_file_path, "rb") as image_file:
        image_data = image_file.read()
        return base64.b64encode(image_data).decode("utf-8")

def generate_markdown_code(image_data: str) -> str:
    """
    Generate the markdown code to render an image.

    Args:
        image_data (str): The base64-encoded image data.

    Returns:
        str: The markdown code to render the image.
    """
    return f"![Image](data:image/png;base64,{image_data})"

def run_multi_agent(llm, message):
    llm_config = {"model": llm}
    
    executor = LocalCommandLineCodeExecutor(
        timeout=60,
        work_dir="coding",
    )
    
    code_executor_agent = ConversableAgent(
        name="code_executor_agent",
        llm_config=False,
        code_execution_config={"executor": executor},
        human_input_mode="NEVER",
        default_auto_reply=
        "Please continue. If everything is done, reply 'TERMINATE'.",
    )
    
    code_writer_agent = AssistantAgent(
        name="code_writer_agent",
        llm_config=llm_config,
        code_execution_config=False,
        human_input_mode="NEVER",
    )
    
    code_writer_agent_system_message = code_writer_agent.system_message
    
    print(code_writer_agent_system_message)
    
    chat_result = code_executor_agent.initiate_chat(
        code_writer_agent,
        message=message,
        max_turns=10
    )

    ###
    #for root, dirs, files in os.walk("."):
    #    for file in files:
    #        print(os.path.join(root, file))
    ###
    
    #png_file = os.path.join("coding", "ytd_stock_gains.png")

    #print("### "+png_file)

    #current_folder = os.getcwd()
    #files_in_folder = os.listdir(current_folder)

    #print(f"Files in {current_folder}:")
    #for file in files_in_folder:
    #    print(file)
    
    #image_path = "/home/user/app/coding/ytd_stock_gains.png"
    #image_path_2 = "/coding/ytd_stock_gains.png"
    #image_path_5 = "coding/ytd_stock_gains.png"
    #image_path_3 = "/app/coding/ytd_stock_gains.png"
    #image_path_4 = "/user/app/coding/ytd_stock_gains.png"

    image_data = read_image_file("/home/user/app/coding/ytd_stock_gains.png")
    markdown_code = generate_markdown_code(image_data)

    return markdown_code
    #image_path = os.path.join('coding', 'ytd_stock_gains.png')
    #image_markdown = f"![YTD Stock Gains]({image_path})"

    #markdown_text = "![YTD Stock Gains](coding/ytd_stock_gains.png)"
    #html = markdown.markdown(markdown_text)
    #print(html)

    #return html #f"![YTD Stock Gains]({image_path})<br />![YTD Stock Gains]({image_path_2})<br />![YTD Stock Gains]({image_path_3})<br />![YTD Stock Gains]({image_path_4})<br />![YTD Stock Gains]({image_path_5})<br />"