mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-29 10:56:22 +02:00
Merge branch 'geekan/dev' into feature/rebuild
This commit is contained in:
commit
5f88e12a7d
62 changed files with 1109 additions and 565 deletions
|
|
@ -35,10 +35,10 @@ async def mermaid_to_file(engine, mermaid_code, output_file_without_suffix, widt
|
|||
# tmp.write_text(mermaid_code, encoding="utf-8")
|
||||
|
||||
if engine == "nodejs":
|
||||
if check_cmd_exists(config.mmdc) != 0:
|
||||
if check_cmd_exists(config.mermaid.path) != 0:
|
||||
logger.warning(
|
||||
"RUN `npm install -g @mermaid-js/mermaid-cli` to install mmdc,"
|
||||
"or consider changing MERMAID_ENGINE to `playwright`, `pyppeteer`, or `ink`."
|
||||
"or consider changing engine to `playwright`, `pyppeteer`, or `ink`."
|
||||
)
|
||||
return -1
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ async def mermaid_to_file(engine, mermaid_code, output_file_without_suffix, widt
|
|||
# Call the `mmdc` command to convert the Mermaid code to a PNG
|
||||
logger.info(f"Generating {output_file}..")
|
||||
|
||||
if config.puppeteer_config:
|
||||
if config.mermaid.puppeteer_config:
|
||||
commands = [
|
||||
config.mmdc,
|
||||
config.mermaid.path,
|
||||
"-p",
|
||||
config.puppeteer_config,
|
||||
config.mermaid.puppeteer_config,
|
||||
"-i",
|
||||
str(tmp),
|
||||
"-o",
|
||||
|
|
@ -62,7 +62,7 @@ async def mermaid_to_file(engine, mermaid_code, output_file_without_suffix, widt
|
|||
str(height),
|
||||
]
|
||||
else:
|
||||
commands = [config.mmdc, "-i", str(tmp), "-o", output_file, "-w", str(width), "-H", str(height)]
|
||||
commands = [config.mermaid.path, "-i", str(tmp), "-o", output_file, "-w", str(width), "-H", str(height)]
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
" ".join(commands), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ async def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048,
|
|||
suffixes = ["png", "svg", "pdf"]
|
||||
__dirname = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if config.pyppeteer_executable_path:
|
||||
if config.mermaid.pyppeteer_path:
|
||||
browser = await launch(
|
||||
headless=True,
|
||||
executablePath=config.pyppeteer_executable_path,
|
||||
executablePath=config.mermaid.pyppeteer_path,
|
||||
args=["--disable-extensions", "--no-sandbox"],
|
||||
)
|
||||
else:
|
||||
logger.error("Please set the environment variable:PYPPETEER_EXECUTABLE_PATH.")
|
||||
logger.error("Please set the var mermaid.pyppeteer_path in the config2.yaml.")
|
||||
return -1
|
||||
page = await browser.newPage()
|
||||
device_scale_factor = 1.0
|
||||
|
|
|
|||
|
|
@ -102,6 +102,13 @@ class ProjectRepo(FileRepository):
|
|||
self.tests = self._git_repo.new_file_repository(relative_path=TEST_CODES_FILE_REPO)
|
||||
self.test_outputs = self._git_repo.new_file_repository(relative_path=TEST_OUTPUTS_FILE_REPO)
|
||||
self._srcs_path = None
|
||||
self.code_files_exists()
|
||||
|
||||
def __str__(self):
|
||||
repo_str = f"ProjectRepo({self._git_repo.workdir})"
|
||||
docs_str = f"Docs({self.docs.all_files})"
|
||||
srcs_str = f"Srcs({self.srcs.all_files})"
|
||||
return f"{repo_str}\n{docs_str}\n{srcs_str}"
|
||||
|
||||
@property
|
||||
async def requirement(self):
|
||||
|
|
|
|||
|
|
@ -119,15 +119,22 @@ def repair_json_format(output: str) -> str:
|
|||
logger.info(f"repair_json_format: {'}]'}")
|
||||
elif output.startswith("{") and output.endswith("]"):
|
||||
output = output[:-1] + "}"
|
||||
|
||||
# remove `#` in output json str, usually appeared in `glm-4`
|
||||
# remove comments in output json string, after json value content, maybe start with #, maybe start with //
|
||||
arr = output.split("\n")
|
||||
new_arr = []
|
||||
for line in arr:
|
||||
idx = line.find("#")
|
||||
if idx >= 0:
|
||||
line = line[:idx]
|
||||
new_arr.append(line)
|
||||
for json_line in arr:
|
||||
# look for # or // comments and make sure they are not inside the string value
|
||||
comment_index = -1
|
||||
for match in re.finditer(r"(\".*?\"|\'.*?\')|(#|//)", json_line):
|
||||
if match.group(1): # if the string value
|
||||
continue
|
||||
if match.group(2): # if comments
|
||||
comment_index = match.start(2)
|
||||
break
|
||||
# if comments, then delete them
|
||||
if comment_index != -1:
|
||||
json_line = json_line[:comment_index].rstrip()
|
||||
new_arr.append(json_line)
|
||||
output = "\n".join(new_arr)
|
||||
return output
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class YamlModelWithoutDefault(YamlModel):
|
|||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_not_default_config(cls, values):
|
||||
"""Check if there is any default config in config.yaml"""
|
||||
"""Check if there is any default config in config2.yaml"""
|
||||
if any(["YOUR" in v for v in values]):
|
||||
raise ValueError("Please set your config in config.yaml")
|
||||
raise ValueError("Please set your config in config2.yaml")
|
||||
return values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue