Update multi_agent.py
Browse files2 unmodified lines3456789101112131411151617141516171819202122232324252610 unmodified lines37383940414041421 unmodified line44454649504748491 unmodified line51525358596061625455565758676869705960617273626364777879808182838485868788899091926566956768986970711 unmodified line737475106107108109110111112767711478791168081822 unmodified linesfrom autogen import ConversableAgent, AssistantAgentfrom autogen.coding import LocalCommandLineCodeExecutor
def read_file(file_path: str) -> str: with open(file_path, "r", encoding="utf-8") as file: return file.read()
def read_image_file(image_file_path: str) -> str: 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:def generate_markdown_image(image_data: str) -> str: return f""
def read_file(file_path: str) -> str: with open(file_path, 'r', encoding='utf-8') as file: return file.read()
def format_as_markdown(code: str) -> str: markdown_code = '```\n' markdown_code += code markdown_code += '\n```' return markdown_code
def run_multi_agent(llm, message): llm_config = {"model": llm} 10 unmodified lines default_auto_reply="Please continue. If everything is done, reply 'TERMINATE'.", )
print("### code_executor_agent.system_message = " + code_executor_agent.system_message)
code_writer_agent = AssistantAgent( name="code_writer_agent", llm_config=llm_config,1 unmodified line human_input_mode="NEVER", ) print("### code_writer_agent.system_message = " + code_writer_agent.system_message) chat_result = code_executor_agent.initiate_chat( code_writer_agent, message=message,1 unmodified line )
image_data = read_image_file("/home/user/app/coding/ytd_stock_gains.png") markdown_code = generate_markdown_code(image_data)
print("### markdown_code = " + markdown_code)
files_in_folder = os.listdir("coding") markdown_code_png = generate_markdown_image(image_data)
file_name_py = "" file_name_sh = "" print(f"Files in {files_in_folder}:") for file in files_in_folder: print(file) if file : for file in os.listdir("coding"): if file: _, file_extension = os.path.splitext(file) if file_extension == ".py": file_name_py = file if file_extension == ".sh": file_name_sh = file print("#" + file_name_py) print("#" + file_name_sh) try: file_path_py = "coding/" + file_name_py print("##" + file_path_py) code_py = read_file(file_path_py) markdown_code_py = format_as_markdown(code_py) print("### " + markdown_code_py) except FileNotFoundError: print(f"Error: File '{file_path_sh}' not found.") except IOError as e: print(f"Error reading file '{file_path_sh}': {e.strerror}") except Exception as e: print(f"An unexpected error occurred: {e}") try: file_path_sh = "coding/" + file_name_sh print("##" + file_path_sh) code_sh = read_file(file_path_sh) markdown_code_sh = format_as_markdown(code_sh) print("### " + markdown_code_sh) except FileNotFoundError: print(f"Error: File '{file_path_sh}' not found.") except IOError as e:1 unmodified line except Exception as e: print(f"An unexpected error occurred: {e}")
#print("### markdown_code = " + markdown_code) #print("###") #print(chat_result) #print("###")
result = markdown_code + "\n" + markdown_code_sh + "\n" + markdown_code_py result = markdown_code_png + "\n" + markdown_code_sh
print("###") print("===") print(result) print("###") print("===") return resultmulti_agent.py+12-48