Merge branch 'dev' into code_intepreter

This commit is contained in:
yzlin 2024-02-01 00:27:42 +08:00
commit ff970ab1c7
20 changed files with 93 additions and 131 deletions

View file

@ -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
)

View file

@ -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

View file

@ -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