mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
another run through for translation.
This commit is contained in:
parent
0eea6bc19f
commit
0d632c7e56
72 changed files with 704 additions and 575 deletions
|
|
@ -15,10 +15,9 @@ from metagpt.logs import logger
|
|||
|
||||
|
||||
def check_cmd_exists(command) -> int:
|
||||
"""Check if a command exists.
|
||||
|
||||
:param command: Command to check.
|
||||
:return: Returns 0 if the command exists, otherwise returns a non-zero value.
|
||||
""" Check if the command exists
|
||||
:param command: Command to be checked
|
||||
:return: Returns 0 if the command exists, non-zero otherwise
|
||||
"""
|
||||
check_command = 'command -v ' + command + ' >/dev/null 2>&1 || { echo >&2 "no mermaid"; exit 1; }'
|
||||
result = os.system(check_command)
|
||||
|
|
@ -29,19 +28,19 @@ class OutputParser:
|
|||
|
||||
@classmethod
|
||||
def parse_blocks(cls, text: str):
|
||||
# First, split the text into different blocks based on "##".
|
||||
# First, split the text into different blocks based on "##"
|
||||
blocks = text.split("##")
|
||||
|
||||
# Create a dictionary to store the title and content of each block.
|
||||
# Create a dictionary to store the title and content of each block
|
||||
block_dict = {}
|
||||
|
||||
# Iterate through all blocks.
|
||||
# Iterate through all blocks
|
||||
for block in blocks:
|
||||
# If the block is not empty, continue processing.
|
||||
# If the block is not empty, continue processing
|
||||
if block.strip() != "":
|
||||
# Split the block's title and content and trim whitespace.
|
||||
# Separate the title and content of the block and trim whitespace
|
||||
block_title, block_content = block.split("\n", 1)
|
||||
# LLM might make mistakes; correct it here.
|
||||
# LLM might have an error, correct it here
|
||||
if block_title[-1] == ":":
|
||||
block_title = block_title[:-1]
|
||||
block_dict[block_title.strip()] = block_content.strip()
|
||||
|
|
@ -85,13 +84,13 @@ class OutputParser:
|
|||
block_dict = cls.parse_blocks(data)
|
||||
parsed_data = {}
|
||||
for block, content in block_dict.items():
|
||||
# Try to remove the code marker.
|
||||
# Try to remove the code marker
|
||||
try:
|
||||
content = cls.parse_code(text=content)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Try to parse the list.
|
||||
# Try to parse the list
|
||||
try:
|
||||
content = cls.parse_file_list(text=content)
|
||||
except Exception:
|
||||
|
|
@ -104,7 +103,7 @@ class OutputParser:
|
|||
block_dict = cls.parse_blocks(data)
|
||||
parsed_data = {}
|
||||
for block, content in block_dict.items():
|
||||
# Try to remove the code marker.
|
||||
# Try to remove the code marker
|
||||
try:
|
||||
content = cls.parse_code(text=content)
|
||||
except Exception:
|
||||
|
|
@ -115,11 +114,18 @@ class OutputParser:
|
|||
else:
|
||||
typing = typing_define
|
||||
if typing == List[str] or typing == List[Tuple[str, str]]:
|
||||
# Try to parse the list.
|
||||
# Try to parse the list
|
||||
try:
|
||||
content = cls.parse_file_list(text=content)
|
||||
except Exception:
|
||||
pass
|
||||
# TODO: Removing extra quotes is risky, will address later
|
||||
# elif typing == str:
|
||||
# # Try to remove extra quotes
|
||||
# try:
|
||||
# content = cls.parse_str(text=content)
|
||||
# except Exception:
|
||||
# pass
|
||||
parsed_data[block] = content
|
||||
return parsed_data
|
||||
|
||||
|
|
@ -136,17 +142,17 @@ class CodeParser:
|
|||
|
||||
@classmethod
|
||||
def parse_blocks(cls, text: str):
|
||||
# First, split the text into different blocks based on "##".
|
||||
# First, split the text into different blocks based on "##"
|
||||
blocks = text.split("##")
|
||||
|
||||
# Create a dictionary to store the title and content of each block.
|
||||
# Create a dictionary to store the title and content of each block
|
||||
block_dict = {}
|
||||
|
||||
# Iterate through all blocks.
|
||||
# Iterate through all blocks
|
||||
for block in blocks:
|
||||
# If the block is not empty, continue processing.
|
||||
# If the block is not empty, continue processing
|
||||
if block.strip() != "":
|
||||
# Split the block's title and content and trim whitespace.
|
||||
# Separate the title and content of the block and trim whitespace
|
||||
block_title, block_content = block.split("\n", 1)
|
||||
block_dict[block_title.strip()] = block_content.strip()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import PROJECT_ROOT
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import check_cmd_exists
|
||||
|
|
@ -39,11 +39,15 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height
|
|||
# Call the `mmdc` command to convert the Mermaid code to a PNG
|
||||
logger.info(f"Generating {output_file}..")
|
||||
if IS_DOCKER == 'true':
|
||||
subprocess.run(['mmdc', '-p', '/app/metagpt/puppeteer-config.json', '-i',
|
||||
subprocess.run(['mmdc', '-p', '/app/metagpt/config/puppeteer-config.json', '-i',
|
||||
str(tmp), '-o', output_file, '-w', str(width), '-H', str(height)])
|
||||
else:
|
||||
subprocess.run(['mmdc', '-i', str(tmp), '-o',
|
||||
output_file, '-w', str(width), '-H', str(height)])
|
||||
if CONFIG.puppeteer_config:
|
||||
subprocess.run([CONFIG.mmdc, '-p', CONFIG.puppeteer_config, '-i', str(tmp), '-o',
|
||||
output_file, '-w', str(width), '-H', str(height)])
|
||||
else:
|
||||
subprocess.run([CONFIG.mmdc, '-i', str(tmp), '-o',
|
||||
output_file, '-w', str(width), '-H', str(height)])
|
||||
return 0
|
||||
|
||||
|
||||
|
|
@ -102,3 +106,4 @@ if __name__ == '__main__':
|
|||
# logger.info(print_members(print_members))
|
||||
mermaid_to_file(MMC1, PROJECT_ROOT / 'tmp/1.png')
|
||||
mermaid_to_file(MMC2, PROJECT_ROOT / 'tmp/2.png')
|
||||
|
||||
|
|
@ -9,13 +9,13 @@
|
|||
import docx
|
||||
|
||||
def read_docx(file_path: str) -> list:
|
||||
"""Open and read a docx file."""
|
||||
"""Open a docx file"""
|
||||
doc = docx.Document(file_path)
|
||||
|
||||
# Create an empty list to store paragraph contents.
|
||||
# Create an empty list to store paragraph contents
|
||||
paragraphs_list = []
|
||||
|
||||
# Iterate through the paragraphs in the document and add their content to the list.
|
||||
# Iterate through the paragraphs in the document and add their content to the list
|
||||
for paragraph in doc.paragraphs:
|
||||
paragraphs_list.append(paragraph.text)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,3 +20,4 @@ class Singleton(abc.ABCMeta, type):
|
|||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue