From aa7ac57b67c2bbbc5245fb2b5009ad775bb0f976 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Wed, 6 Mar 2024 19:04:36 +0100 Subject: [PATCH] community: Implement lazy_load() for TrelloLoader (#18658) Covered by `tests/unit_tests/document_loaders/test_trello.py` --- .../langchain_community/document_loaders/trello.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/document_loaders/trello.py b/libs/community/langchain_community/document_loaders/trello.py index 4fb7a47426a..a66c0726743 100644 --- a/libs/community/langchain_community/document_loaders/trello.py +++ b/libs/community/langchain_community/document_loaders/trello.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, List, Literal, Optional, Tuple +from typing import TYPE_CHECKING, Any, Iterator, Literal, Optional, Tuple from langchain_core.documents import Document from langchain_core.utils import get_from_env @@ -89,7 +89,7 @@ class TrelloLoader(BaseLoader): client = TrelloClient(api_key=api_key, token=token) return cls(client, board_name, **kwargs) - def load(self) -> List[Document]: + def lazy_load(self) -> Iterator[Document]: """Loads all cards from the specified Trello board. You can filter the cards, metadata and text included by using the optional @@ -111,7 +111,8 @@ class TrelloLoader(BaseLoader): list_dict = {list_item.id: list_item.name for list_item in board.list_lists()} # Get Cards on the board cards = board.get_cards(card_filter=self.card_filter) - return [self._card_to_doc(card, list_dict) for card in cards] + for card in cards: + yield self._card_to_doc(card, list_dict) def _get_board(self) -> Board: # Find the first board with a matching name