skip large size svg (#869)
Co-authored-by: LawyZheng <lawyzheng1106@gmail.com>
This commit is contained in:
@@ -122,6 +122,8 @@ class Settings(BaseSettings):
|
||||
VERIFICATION_CODE_INITIAL_WAIT_TIME_SECS: int = 40
|
||||
VERIFICATION_CODE_POLLING_TIMEOUT_MINS: int = 5
|
||||
|
||||
SVG_MAX_LENGTH: int = 100000
|
||||
|
||||
def is_cloud_environment(self) -> bool:
|
||||
"""
|
||||
:return: True if env is not local, else False
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Dict, List
|
||||
import structlog
|
||||
from playwright.async_api import Page
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import SKYVERN_ID_ATTR
|
||||
from skyvern.exceptions import StepUnableToExecuteError, SVGConversionFailed
|
||||
from skyvern.forge import app
|
||||
@@ -62,6 +63,9 @@ async def _convert_svg_to_string(task: Task, step: Step, organization: Organizat
|
||||
if element.get("tagName") != "svg":
|
||||
return
|
||||
|
||||
if element.get("isDropped", False):
|
||||
return
|
||||
|
||||
element_id = element.get("id", "")
|
||||
svg_element = _remove_skyvern_attributes(element)
|
||||
svg_html = json_to_html(svg_element)
|
||||
@@ -83,6 +87,17 @@ async def _convert_svg_to_string(task: Task, step: Step, organization: Organizat
|
||||
if svg_shape:
|
||||
LOG.debug("SVG loaded from cache", element_id=element_id, shape=svg_shape)
|
||||
else:
|
||||
if len(svg_html) > settings.SVG_MAX_LENGTH:
|
||||
# TODO: implement a fallback solution for "too large" case, maybe convert by screenshot
|
||||
LOG.warning(
|
||||
"SVG element is too large to convert, going to drop the svg element.",
|
||||
element_id=element_id,
|
||||
length=len(svg_html),
|
||||
)
|
||||
del element["children"]
|
||||
element["isDropped"] = True
|
||||
return
|
||||
|
||||
LOG.debug("call LLM to convert SVG to string shape", element_id=element_id)
|
||||
svg_convert_prompt = prompt_engine.load_prompt("svg-convert", svg_element=svg_html)
|
||||
|
||||
|
||||
@@ -86,6 +86,12 @@ def build_attribute(key: str, value: Any) -> str:
|
||||
|
||||
|
||||
def json_to_html(element: dict, need_skyvern_attrs: bool = True) -> str:
|
||||
"""
|
||||
if element is flagged as dropped, the html format is empty
|
||||
"""
|
||||
if element.get("isDropped", False):
|
||||
return ""
|
||||
|
||||
attributes: dict[str, Any] = copy.deepcopy(element.get("attributes", {}))
|
||||
|
||||
if need_skyvern_attrs:
|
||||
|
||||
Reference in New Issue
Block a user