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
This commit is contained in:
BeatrixCohere 2024-01-17 17:11:00 +00:00 committed by GitHub
parent d91126fc64
commit b0c3e3db2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,