bstraehle commited on
Commit
9ea371a
1 Parent(s): 646ae39

Update multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +12 -48
multi_agent.py CHANGED
@@ -3,24 +3,24 @@ import base64, os
3
  from autogen import ConversableAgent, AssistantAgent
4
  from autogen.coding import LocalCommandLineCodeExecutor
5
 
 
 
 
 
6
  def read_image_file(image_file_path: str) -> str:
7
  with open(image_file_path, "rb") as image_file:
8
  image_data = image_file.read()
9
  return base64.b64encode(image_data).decode("utf-8")
10
 
11
- def generate_markdown_code(image_data: str) -> str:
12
  return f"![Image](data:image/png;base64,{image_data})"
13
 
14
- def read_file(file_path: str) -> str:
15
- with open(file_path, 'r', encoding='utf-8') as file:
16
- return file.read()
17
-
18
  def format_as_markdown(code: str) -> str:
19
  markdown_code = '```\n'
20
  markdown_code += code
21
  markdown_code += '\n```'
22
  return markdown_code
23
-
24
  def run_multi_agent(llm, message):
25
  llm_config = {"model": llm}
26
 
@@ -37,8 +37,6 @@ def run_multi_agent(llm, message):
37
  default_auto_reply="Please continue. If everything is done, reply 'TERMINATE'.",
38
  )
39
 
40
- print("### code_executor_agent.system_message = " + code_executor_agent.system_message)
41
-
42
  code_writer_agent = AssistantAgent(
43
  name="code_writer_agent",
44
  llm_config=llm_config,
@@ -46,8 +44,6 @@ def run_multi_agent(llm, message):
46
  human_input_mode="NEVER",
47
  )
48
 
49
- print("### code_writer_agent.system_message = " + code_writer_agent.system_message)
50
-
51
  chat_result = code_executor_agent.initiate_chat(
52
  code_writer_agent,
53
  message=message,
@@ -55,47 +51,21 @@ def run_multi_agent(llm, message):
55
  )
56
 
57
  image_data = read_image_file("/home/user/app/coding/ytd_stock_gains.png")
58
- markdown_code = generate_markdown_code(image_data)
59
-
60
- print("### markdown_code = " + markdown_code)
61
-
62
- files_in_folder = os.listdir("coding")
63
 
64
  file_name_py = ""
65
  file_name_sh = ""
66
 
67
- print(f"Files in {files_in_folder}:")
68
- for file in files_in_folder:
69
- print(file)
70
- if file :
71
  _, file_extension = os.path.splitext(file)
72
- if file_extension == ".py":
73
- file_name_py = file
74
  if file_extension == ".sh":
75
  file_name_sh = file
76
 
77
- print("#" + file_name_py)
78
- print("#" + file_name_sh)
79
-
80
- try:
81
- file_path_py = "coding/" + file_name_py
82
- print("##" + file_path_py)
83
- code_py = read_file(file_path_py)
84
- markdown_code_py = format_as_markdown(code_py)
85
- print("### " + markdown_code_py)
86
- except FileNotFoundError:
87
- print(f"Error: File '{file_path_sh}' not found.")
88
- except IOError as e:
89
- print(f"Error reading file '{file_path_sh}': {e.strerror}")
90
- except Exception as e:
91
- print(f"An unexpected error occurred: {e}")
92
-
93
  try:
94
  file_path_sh = "coding/" + file_name_sh
95
- print("##" + file_path_sh)
96
  code_sh = read_file(file_path_sh)
97
  markdown_code_sh = format_as_markdown(code_sh)
98
- print("### " + markdown_code_sh)
99
  except FileNotFoundError:
100
  print(f"Error: File '{file_path_sh}' not found.")
101
  except IOError as e:
@@ -103,16 +73,10 @@ def run_multi_agent(llm, message):
103
  except Exception as e:
104
  print(f"An unexpected error occurred: {e}")
105
 
106
- #print("### markdown_code = " + markdown_code)
107
-
108
- #print("###")
109
- #print(chat_result)
110
- #print("###")
111
-
112
- result = markdown_code + "\n" + markdown_code_sh + "\n" + markdown_code_py
113
 
114
- print("###")
115
  print(result)
116
- print("###")
117
 
118
  return result
 
3
  from autogen import ConversableAgent, AssistantAgent
4
  from autogen.coding import LocalCommandLineCodeExecutor
5
 
6
+ def read_file(file_path: str) -> str:
7
+ with open(file_path, "r", encoding="utf-8") as file:
8
+ return file.read()
9
+
10
  def read_image_file(image_file_path: str) -> str:
11
  with open(image_file_path, "rb") as image_file:
12
  image_data = image_file.read()
13
  return base64.b64encode(image_data).decode("utf-8")
14
 
15
+ def generate_markdown_image(image_data: str) -> str:
16
  return f"![Image](data:image/png;base64,{image_data})"
17
 
 
 
 
 
18
  def format_as_markdown(code: str) -> str:
19
  markdown_code = '```\n'
20
  markdown_code += code
21
  markdown_code += '\n```'
22
  return markdown_code
23
+
24
  def run_multi_agent(llm, message):
25
  llm_config = {"model": llm}
26
 
 
37
  default_auto_reply="Please continue. If everything is done, reply 'TERMINATE'.",
38
  )
39
 
 
 
40
  code_writer_agent = AssistantAgent(
41
  name="code_writer_agent",
42
  llm_config=llm_config,
 
44
  human_input_mode="NEVER",
45
  )
46
 
 
 
47
  chat_result = code_executor_agent.initiate_chat(
48
  code_writer_agent,
49
  message=message,
 
51
  )
52
 
53
  image_data = read_image_file("/home/user/app/coding/ytd_stock_gains.png")
54
+ markdown_code_png = generate_markdown_image(image_data)
 
 
 
 
55
 
56
  file_name_py = ""
57
  file_name_sh = ""
58
 
59
+ for file in os.listdir("coding"):
60
+ if file:
 
 
61
  _, file_extension = os.path.splitext(file)
 
 
62
  if file_extension == ".sh":
63
  file_name_sh = file
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  try:
66
  file_path_sh = "coding/" + file_name_sh
 
67
  code_sh = read_file(file_path_sh)
68
  markdown_code_sh = format_as_markdown(code_sh)
 
69
  except FileNotFoundError:
70
  print(f"Error: File '{file_path_sh}' not found.")
71
  except IOError as e:
 
73
  except Exception as e:
74
  print(f"An unexpected error occurred: {e}")
75
 
76
+ result = markdown_code_png + "\n" + markdown_code_sh
 
 
 
 
 
 
77
 
78
+ print("===")
79
  print(result)
80
+ print("===")
81
 
82
  return result