mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 04:07:54 +00:00
langchain_core: add file_type
option to make file type default as png
(#27855)
Thank you for contributing to LangChain! - [ ] **PR title**: "package: description" - Where "package" is whichever of langchain, community, core, etc. is being modified. Use "docs: ..." for purely docs changes, "templates: ..." for template changes, "infra: ..." for CI changes. - Example: "community: add foobar LLM" - [ ] **description** langchain_core.runnables.graph_mermaid.draw_mermaid_png calls this function, but the Mermaid API returns JPEG by default. To be consistent, add the option `file_type` with the default `png` type. - [ ] **Add tests and docs**: If you're adding a new integration, please include With this small change, I didn't add tests and docs. - [ ] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: One long sentence was divided into two. Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
This commit is contained in:
parent
0f85dea8c8
commit
482c168b3e
@ -2,7 +2,7 @@ import asyncio
|
||||
import base64
|
||||
import re
|
||||
from dataclasses import asdict
|
||||
from typing import Optional
|
||||
from typing import Literal, Optional
|
||||
|
||||
from langchain_core.runnables.graph import (
|
||||
CurveStyle,
|
||||
@ -306,6 +306,7 @@ def _render_mermaid_using_api(
|
||||
mermaid_syntax: str,
|
||||
output_file_path: Optional[str] = None,
|
||||
background_color: Optional[str] = "white",
|
||||
file_type: Optional[Literal["jpeg", "png", "webp"]] = "png",
|
||||
) -> bytes:
|
||||
"""Renders Mermaid graph using the Mermaid.INK API."""
|
||||
try:
|
||||
@ -329,7 +330,8 @@ def _render_mermaid_using_api(
|
||||
background_color = f"!{background_color}"
|
||||
|
||||
image_url = (
|
||||
f"https://mermaid.ink/img/{mermaid_syntax_encoded}?bgColor={background_color}"
|
||||
f"https://mermaid.ink/img/{mermaid_syntax_encoded}"
|
||||
f"?type={file_type}&bgColor={background_color}"
|
||||
)
|
||||
response = requests.get(image_url, timeout=10)
|
||||
if response.status_code == 200:
|
||||
|
Loading…
Reference in New Issue
Block a user