浏览代码

feat: optimize output parse (#906)

tags/0.3.15
takatost 2 年前
父节点
当前提交
d9afebe216
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2
    2
      api/core/agent/agent/output_parser/structured_chat.py

+ 2
- 2
api/core/agent/agent/output_parser/structured_chat.py 查看文件

class StructuredChatOutputParser(LCStructuredChatOutputParser): class StructuredChatOutputParser(LCStructuredChatOutputParser):
def parse(self, text: str) -> Union[AgentAction, AgentFinish]: def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
try: 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: if action_match is not None:
response = json.loads(action_match.group(2).strip(), strict=False) response = json.loads(action_match.group(2).strip(), strict=False)
if isinstance(response, list): if isinstance(response, list):
else: else:
return AgentFinish({"output": text}, text) return AgentFinish({"output": text}, text)
except Exception as e: except Exception as e:
raise OutputParserException(f"Could not parse LLM output: {text}") from e
raise OutputParserException(f"Could not parse LLM output: {text}")

正在加载...
取消
保存