Update multi_agent.py
Browse files- multi_agent.py +46 -16
multi_agent.py
CHANGED
@@ -4,6 +4,32 @@ from autogen.coding import LocalCommandLineCodeExecutor
|
|
4 |
import markdown, os
|
5 |
#from IPython.display import Image
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def run_multi_agent(llm, message):
|
8 |
llm_config = {"model": llm}
|
9 |
|
@@ -48,24 +74,28 @@ def run_multi_agent(llm, message):
|
|
48 |
|
49 |
#print("### "+png_file)
|
50 |
|
51 |
-
current_folder = os.getcwd()
|
52 |
-
files_in_folder = os.listdir(current_folder)
|
53 |
|
54 |
-
print(f"Files in {current_folder}:")
|
55 |
-
for file in files_in_folder:
|
56 |
-
|
57 |
|
58 |
-
image_path = "/home/user/app/coding/ytd_stock_gains.png"
|
59 |
-
image_path_2 = "/coding/ytd_stock_gains.png"
|
60 |
-
image_path_5 = "coding/ytd_stock_gains.png"
|
61 |
-
image_path_3 = "/app/coding/ytd_stock_gains.png"
|
62 |
-
image_path_4 = "/user/app/coding/ytd_stock_gains.png"
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
-
markdown_text = "![YTD Stock Gains](coding/ytd_stock_gains.png)"
|
68 |
-
html = markdown.markdown(markdown_text)
|
69 |
-
print(html)
|
70 |
|
71 |
-
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 />"
|
|
|
4 |
import markdown, os
|
5 |
#from IPython.display import Image
|
6 |
|
7 |
+
def read_image_file(image_file_path: str) -> str:
|
8 |
+
"""
|
9 |
+
Read a PNG image file from the local filesystem and encode it as a base64 string.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
image_file_path (str): The local file path of the image.
|
13 |
+
|
14 |
+
Returns:
|
15 |
+
str: The base64-encoded image data.
|
16 |
+
"""
|
17 |
+
with open(image_file_path, "rb") as image_file:
|
18 |
+
image_data = image_file.read()
|
19 |
+
return base64.b64encode(image_data).decode("utf-8")
|
20 |
+
|
21 |
+
def generate_markdown_code(image_data: str) -> str:
|
22 |
+
"""
|
23 |
+
Generate the markdown code to render an image.
|
24 |
+
|
25 |
+
Args:
|
26 |
+
image_data (str): The base64-encoded image data.
|
27 |
+
|
28 |
+
Returns:
|
29 |
+
str: The markdown code to render the image.
|
30 |
+
"""
|
31 |
+
return f"![Image](data:image/png;base64,{image_data})"
|
32 |
+
|
33 |
def run_multi_agent(llm, message):
|
34 |
llm_config = {"model": llm}
|
35 |
|
|
|
74 |
|
75 |
#print("### "+png_file)
|
76 |
|
77 |
+
#current_folder = os.getcwd()
|
78 |
+
#files_in_folder = os.listdir(current_folder)
|
79 |
|
80 |
+
#print(f"Files in {current_folder}:")
|
81 |
+
#for file in files_in_folder:
|
82 |
+
# print(file)
|
83 |
|
84 |
+
#image_path = "/home/user/app/coding/ytd_stock_gains.png"
|
85 |
+
#image_path_2 = "/coding/ytd_stock_gains.png"
|
86 |
+
#image_path_5 = "coding/ytd_stock_gains.png"
|
87 |
+
#image_path_3 = "/app/coding/ytd_stock_gains.png"
|
88 |
+
#image_path_4 = "/user/app/coding/ytd_stock_gains.png"
|
89 |
+
|
90 |
+
image_data = read_image_file("/home/user/app/coding/ytd_stock_gains.png")
|
91 |
+
markdown_code = generate_markdown_code(image_data)
|
92 |
|
93 |
+
return markdown_code
|
94 |
+
#image_path = os.path.join('coding', 'ytd_stock_gains.png')
|
95 |
+
#image_markdown = f"![YTD Stock Gains]({image_path})"
|
96 |
|
97 |
+
#markdown_text = "![YTD Stock Gains](coding/ytd_stock_gains.png)"
|
98 |
+
#html = markdown.markdown(markdown_text)
|
99 |
+
#print(html)
|
100 |
|
101 |
+
#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 />"
|