Update multi_agent.py
Browse files- multi_agent.py +26 -8
multi_agent.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import base64, json, os
|
2 |
|
3 |
from autogen import ConversableAgent, AssistantAgent
|
4 |
from autogen.coding import LocalCommandLineCodeExecutor
|
@@ -20,6 +20,24 @@ def format_as_markdown(code: str) -> str:
|
|
20 |
markdown_code += code
|
21 |
markdown_code += '\n```'
|
22 |
return markdown_code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def run_multi_agent(llm, task):
|
25 |
llm_config = {"model": llm}
|
@@ -58,13 +76,13 @@ def run_multi_agent(llm, task):
|
|
58 |
chat += f"**{message['role'].replace('assistant', 'Code Executor').replace('user', 'Code Writer')}**\n{message['content']}\n\n"
|
59 |
first_message = False
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
if
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
image_data = read_image_file(f"/home/user/app/coding/{file_name_png}")
|
70 |
markdown_code_png = generate_markdown_image(image_data)
|
|
|
1 |
+
import base64, datetime, json, os
|
2 |
|
3 |
from autogen import ConversableAgent, AssistantAgent
|
4 |
from autogen.coding import LocalCommandLineCodeExecutor
|
|
|
20 |
markdown_code += code
|
21 |
markdown_code += '\n```'
|
22 |
return markdown_code
|
23 |
+
|
24 |
+
def get_latest_file(directory, file_extension):
|
25 |
+
latest_file = None
|
26 |
+
latest_date = datetime.datetime.min
|
27 |
+
|
28 |
+
for file in os.listdir(directory):
|
29 |
+
if file:
|
30 |
+
_, file_ext = os.path.splitext(file)
|
31 |
+
|
32 |
+
if file_ext == file_extension:
|
33 |
+
file_path = os.path.join(directory, file)
|
34 |
+
file_date = datetime.datetime.fromtimestamp(os.path.getmtime(file_path))
|
35 |
+
|
36 |
+
if file_date > latest_date:
|
37 |
+
latest_date = file_date
|
38 |
+
latest_file = file
|
39 |
+
|
40 |
+
return latest_file
|
41 |
|
42 |
def run_multi_agent(llm, task):
|
43 |
llm_config = {"model": llm}
|
|
|
76 |
chat += f"**{message['role'].replace('assistant', 'Code Executor').replace('user', 'Code Writer')}**\n{message['content']}\n\n"
|
77 |
first_message = False
|
78 |
|
79 |
+
#for file in os.listdir("coding"):
|
80 |
+
# if file:
|
81 |
+
# _, file_extension = os.path.splitext(file)
|
82 |
+
# if file_extension == ".png":
|
83 |
+
# file_name_png = file
|
84 |
+
|
85 |
+
file_name_png = get_latest_file("coding", ".png")
|
86 |
|
87 |
image_data = read_image_file(f"/home/user/app/coding/{file_name_png}")
|
88 |
markdown_code_png = generate_markdown_image(image_data)
|