From 8ae9b71e41d1598006163ccf899ac71d4878f7fa Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Thu, 28 Sep 2023 06:42:59 -0700 Subject: [PATCH] Async support for OpenAIFunctionsAgentOutputParser (#11140) --- .../langchain/agents/output_parsers/openai_functions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/langchain/langchain/agents/output_parsers/openai_functions.py b/libs/langchain/langchain/agents/output_parsers/openai_functions.py index a99453be51..7a2a2702d6 100644 --- a/libs/langchain/langchain/agents/output_parsers/openai_functions.py +++ b/libs/langchain/langchain/agents/output_parsers/openai_functions.py @@ -1,3 +1,4 @@ +import asyncio import json from json import JSONDecodeError from typing import List, Union @@ -80,5 +81,12 @@ class OpenAIFunctionsAgentOutputParser(AgentOutputParser): message = result[0].message return self._parse_ai_message(message) + async def aparse_result( + self, result: List[Generation] + ) -> Union[AgentAction, AgentFinish]: + return await asyncio.get_running_loop().run_in_executor( + None, self.parse_result, result + ) + def parse(self, text: str) -> Union[AgentAction, AgentFinish]: raise ValueError("Can only parse messages")