From d9afebe216ae76b1c3493b63bf8916cac3449cc9 Mon Sep 17 00:00:00 2001 From: takatost Date: Fri, 18 Aug 2023 17:00:40 +0800 Subject: [PATCH] feat: optimize output parse (#906) --- api/core/agent/agent/output_parser/structured_chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/core/agent/agent/output_parser/structured_chat.py b/api/core/agent/agent/output_parser/structured_chat.py index e2841b6720..f0332a007a 100644 --- a/api/core/agent/agent/output_parser/structured_chat.py +++ b/api/core/agent/agent/output_parser/structured_chat.py @@ -10,7 +10,7 @@ from langchain.schema import AgentAction, AgentFinish, OutputParserException class StructuredChatOutputParser(LCStructuredChatOutputParser): def parse(self, text: str) -> Union[AgentAction, AgentFinish]: try: - action_match = re.search(r"```(.*?)\n?(.*?)```", text, re.DOTALL) + action_match = re.search(r"```(\w*)\n?({.*?)```", text, re.DOTALL) if action_match is not None: response = json.loads(action_match.group(2).strip(), strict=False) if isinstance(response, list): @@ -26,4 +26,4 @@ class StructuredChatOutputParser(LCStructuredChatOutputParser): else: return AgentFinish({"output": text}, text) except Exception as e: - raise OutputParserException(f"Could not parse LLM output: {text}") from e + raise OutputParserException(f"Could not parse LLM output: {text}")