Skip to content

The agent engineering platform.

Add apredict_and_parse to LLM (#2164)

Tim Asp6be67279fba8
diff --git a/langchain/chains/llm.py b/langchain/chains/llm.py
index 46b3cfb7ce..62cc7a9112 100644
--- a/langchain/chains/llm.py
+++ b/langchain/chains/llm.py
@@ -174,6 +174,16 @@ class LLMChain(Chain, BaseModel):
else:
return result
+ async def apredict_and_parse(
+ self, **kwargs: Any
+ ) -> Union[str, List[str], Dict[str, str]]:
+ """Call apredict and then parse the results."""
+ result = await self.apredict(**kwargs)
+ if self.prompt.output_parser is not None:
+ return self.prompt.output_parser.parse(result)
+ else:
+ return result
+
def apply_and_parse(
self, input_list: List[Dict[str, Any]]
) -> Sequence[Union[str, List[str], Dict[str, str]]]: