From c51753250d706e130581687e6eef52c86e232346 Mon Sep 17 00:00:00 2001 From: Ankush Gola <9536492+agola11@users.noreply.github.com> Date: Mon, 10 Apr 2023 01:28:16 +0200 Subject: [PATCH] Add async call to APIChain. (#2583) (#2644) Co-authored-by: Yan <32036413+Yan-Zero@users.noreply.github.com> --- langchain/chains/api/base.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/langchain/chains/api/base.py b/langchain/chains/api/base.py index 212982a5..47f37b73 100644 --- a/langchain/chains/api/base.py +++ b/langchain/chains/api/base.py @@ -81,6 +81,26 @@ class APIChain(Chain): ) return {self.output_key: answer} + async def _acall(self, inputs: Dict[str, str]) -> Dict[str, str]: + question = inputs[self.question_key] + api_url = await self.api_request_chain.apredict( + question=question, api_docs=self.api_docs + ) + self.callback_manager.on_text( + api_url, color="green", end="\n", verbose=self.verbose + ) + api_response = await self.requests_wrapper.aget(api_url) + self.callback_manager.on_text( + api_response, color="yellow", end="\n", verbose=self.verbose + ) + answer = await self.api_answer_chain.apredict( + question=question, + api_docs=self.api_docs, + api_url=api_url, + api_response=api_response, + ) + return {self.output_key: answer} + @classmethod def from_llm_and_api_docs( cls,