Update multi_agent.py
Browse files2 unmodified lines3456789101112131415161718192021222324252610 unmodified lines37383940414243441 unmodified line46474849505152531 unmodified line5556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011 unmodified line1031041051061071081091101111121131141151161171182 unmodified linesfrom autogen import ConversableAgent, AssistantAgentfrom autogen.coding import LocalCommandLineCodeExecutordef 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: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 += codemarkdown_code += '\n```'return markdown_codedef run_multi_agent(llm, message):llm_config = {"model": llm}10 unmodified linesdefault_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 linehuman_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")file_name_py = ""file_name_sh = ""print(f"Files in {files_in_folder}:")for file in files_in_folder:print(file)if file :_, file_extension = os.path.splitext(file)if file_extension == ".py":file_name_py = fileif file_extension == ".sh":file_name_sh = fileprint("#" + file_name_py)print("#" + file_name_sh)try:file_path_py = "coding/" + file_name_pyprint("##" + 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_shprint("##" + 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 lineexcept 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_pyprint("###")print(result)print("###")return result2 unmodified lines3456789101112131415161718192021222324252610 unmodified lines3738394041421 unmodified line4445464748491 unmodified line5152535455565758596061626364656667686970711 unmodified line737475767778798081822 unmodified linesfrom autogen import ConversableAgent, AssistantAgentfrom autogen.coding import LocalCommandLineCodeExecutordef 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_image(image_data: str) -> str:return f""def format_as_markdown(code: str) -> str:markdown_code = '```\n'markdown_code += codemarkdown_code += '\n```'return markdown_codedef run_multi_agent(llm, message):llm_config = {"model": llm}10 unmodified linesdefault_auto_reply="Please continue. If everything is done, reply 'TERMINATE'.",)code_writer_agent = AssistantAgent(name="code_writer_agent",llm_config=llm_config,1 unmodified linehuman_input_mode="NEVER",)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_png = generate_markdown_image(image_data)file_name_py = ""file_name_sh = ""for file in os.listdir("coding"):if file:_, file_extension = os.path.splitext(file)if file_extension == ".sh":file_name_sh = filetry:file_path_sh = "coding/" + file_name_shcode_sh = read_file(file_path_sh)markdown_code_sh = format_as_markdown(code_sh)except FileNotFoundError:print(f"Error: File '{file_path_sh}' not found.")except IOError as e:1 unmodified lineexcept Exception as e:print(f"An unexpected error occurred: {e}")result = markdown_code_png + "\n" + markdown_code_shprint("===")print(result)print("===")return result
multi_agent.py+12-48