Update multi_agent.py
Browse files- multi_agent.py +16 -12
multi_agent.py
CHANGED
|
@@ -12,18 +12,15 @@ def generate_markdown_code(image_data: str) -> str:
|
|
| 12 |
return f""
|
| 13 |
|
| 14 |
def read_python_file(file_path: str) -> str:
|
| 15 |
-
"""
|
| 16 |
-
Reads a Python file and returns its contents as a string.
|
| 17 |
-
|
| 18 |
-
Args:
|
| 19 |
-
file_path (str): The path to the Python file.
|
| 20 |
-
|
| 21 |
-
Returns:
|
| 22 |
-
str: The contents of the Python file.
|
| 23 |
-
"""
|
| 24 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 25 |
return file.read()
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def format_as_markdown(code: str) -> str:
|
| 28 |
"""
|
| 29 |
Formats a string of Python code as Markdown.
|
|
@@ -84,15 +81,22 @@ def run_multi_agent(llm, message):
|
|
| 84 |
print(f"Files in {current_folder}:")
|
| 85 |
for file in files_in_folder:
|
| 86 |
print(file)
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
file_path = "coding/
|
| 89 |
code = read_python_file(file_path)
|
| 90 |
markdown_code = format_as_markdown(code)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
print("###")
|
| 95 |
-
print(chat_result)
|
| 96 |
print("###")
|
| 97 |
|
| 98 |
return markdown_code
|
|
|
|
| 12 |
return f""
|
| 13 |
|
| 14 |
def read_python_file(file_path: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 16 |
return file.read()
|
| 17 |
|
| 18 |
+
def read_py_file(folder_path: str, extension: str) -> str:
|
| 19 |
+
for filename in os.listdir(folder_path):
|
| 20 |
+
if filename.endswith(extension):
|
| 21 |
+
with open(os.path.join(folder_path, filename), "r", encoding="utf-8") as file:
|
| 22 |
+
return file.read()
|
| 23 |
+
|
| 24 |
def format_as_markdown(code: str) -> str:
|
| 25 |
"""
|
| 26 |
Formats a string of Python code as Markdown.
|
|
|
|
| 81 |
print(f"Files in {current_folder}:")
|
| 82 |
for file in files_in_folder:
|
| 83 |
print(file)
|
| 84 |
+
|
| 85 |
+
file_name_py = read_py_file("coding", ".py")
|
| 86 |
+
file_name_sh = read_py_file("coding", ".sh")
|
| 87 |
|
| 88 |
+
file_path = "coding/" + file_name_py
|
| 89 |
code = read_python_file(file_path)
|
| 90 |
markdown_code = format_as_markdown(code)
|
| 91 |
+
|
| 92 |
+
file_path = "coding/" + file_name_sh
|
| 93 |
+
code = read_python_file(file_path)
|
| 94 |
+
markdown_code += "<br />" format_as_markdown(code)
|
| 95 |
|
| 96 |
+
print("### markdown_code = " + markdown_code)
|
| 97 |
|
| 98 |
print("###")
|
| 99 |
+
#print(chat_result)
|
| 100 |
print("###")
|
| 101 |
|
| 102 |
return markdown_code
|