Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-3915 Remove incomplete json fixing logic -- models have gotten better (#1121)
Shuchang Zheng2ac8a1a7d0ca
diff --git a/skyvern/forge/sdk/api/llm/utils.py b/skyvern/forge/sdk/api/llm/utils.pyindex c0fee72fa..1f7ba93d4 100644--- a/skyvern/forge/sdk/api/llm/utils.py+++ b/skyvern/forge/sdk/api/llm/utils.py@@ -52,13 +52,16 @@ def parse_api_response(response: litellm.ModelResponse, add_assistant_prefix: boif add_assistant_prefix:content = "{" + contentcontent = try_to_extract_json_from_markdown_format(content)- content = replace_useless_text_around_json(content)if not content:raise EmptyLLMResponseError(str(response))return commentjson.loads(content)except Exception as e:if content:- LOG.warning("Failed to parse LLM response. Will retry auto-fixing the response for unescaped quotes.")+ LOG.warning(+ "Failed to parse LLM response. Will retry auto-fixing the response for unescaped quotes.",+ exc_info=True,+ content=content,+ )try:return fix_and_parse_json_string(content)except Exception as e2:@@ -180,12 +183,6 @@ def fix_and_parse_json_string(json_string: str) -> dict[str, Any]:return fix_cutoff_json(json_string, error_position)-def replace_useless_text_around_json(input_string: str) -> str:- first_occurrence_of_brace = input_string.find("{")- last_occurrence_of_brace = input_string.rfind("}")- return input_string[first_occurrence_of_brace : last_occurrence_of_brace + 1]--def try_to_extract_json_from_markdown_format(text: str) -> str:pattern = r"```json\s*(.*?)\s*```"match = re.search(pattern, text, re.DOTALL)