From b0c3e3db2b24dd010d2994bb2bd3853aa02421ba Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:11:00 +0000 Subject: [PATCH] community[patch]: Handle when documents are not provided in the Cohere response (#16144) - **Description:** This handles the cohere response when documents aren't included in the response - **Issue:** N/A - **Dependencies:** N/A - **Twitter handle:** N/A --- .../retrievers/cohere_rag_retriever.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/community/langchain_community/retrievers/cohere_rag_retriever.py b/libs/community/langchain_community/retrievers/cohere_rag_retriever.py index 39dcc30f3b4..91f4c3a0886 100644 --- a/libs/community/langchain_community/retrievers/cohere_rag_retriever.py +++ b/libs/community/langchain_community/retrievers/cohere_rag_retriever.py @@ -17,10 +17,14 @@ if TYPE_CHECKING: def _get_docs(response: Any) -> List[Document]: - docs = [ - Document(page_content=doc["snippet"], metadata=doc) - for doc in response.generation_info["documents"] - ] + docs = ( + [] + if "documents" not in response.generation_info + else [ + Document(page_content=doc["snippet"], metadata=doc) + for doc in response.generation_info["documents"] + ] + ) docs.append( Document( page_content=response.message.content,