From 2184e3a4005f5c48126523cce92930fca6a31760 Mon Sep 17 00:00:00 2001 From: Sam Groenjes Date: Fri, 11 Aug 2023 00:50:39 -0500 Subject: [PATCH] Fix IndexError when input_list is Empty in prep_prompts (#5769) This MR corrects the IndexError arising in prep_prompts method when no documents are returned from a similarity search. Fixes #1733 Co-authored-by: Sam Groenjes Co-authored-by: Bagatur --- libs/langchain/langchain/chains/llm.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/langchain/langchain/chains/llm.py b/libs/langchain/langchain/chains/llm.py index b1bbfae78a..18029309b6 100644 --- a/libs/langchain/langchain/chains/llm.py +++ b/libs/langchain/langchain/chains/llm.py @@ -127,6 +127,8 @@ class LLMChain(Chain): ) -> Tuple[List[PromptValue], Optional[List[str]]]: """Prepare prompts from inputs.""" stop = None + if len(input_list) == 0: + return [], stop if "stop" in input_list[0]: stop = input_list[0]["stop"] prompts = [] @@ -151,6 +153,8 @@ class LLMChain(Chain): ) -> Tuple[List[PromptValue], Optional[List[str]]]: """Prepare prompts from inputs.""" stop = None + if len(input_list) == 0: + return [], stop if "stop" in input_list[0]: stop = input_list[0]["stop"] prompts = []