community: Implement lazy_load() for TrelloLoader (#18658)

Covered by `tests/unit_tests/document_loaders/test_trello.py`
This commit is contained in:
Christophe Bornet 2024-03-06 19:04:36 +01:00 committed by GitHub
parent 302985fea1
commit aa7ac57b67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
from __future__ import annotations 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.documents import Document
from langchain_core.utils import get_from_env from langchain_core.utils import get_from_env
@ -89,7 +89,7 @@ class TrelloLoader(BaseLoader):
client = TrelloClient(api_key=api_key, token=token) client = TrelloClient(api_key=api_key, token=token)
return cls(client, board_name, **kwargs) 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. """Loads all cards from the specified Trello board.
You can filter the cards, metadata and text included by using the optional 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()} list_dict = {list_item.id: list_item.name for list_item in board.list_lists()}
# Get Cards on the board # Get Cards on the board
cards = board.get_cards(card_filter=self.card_filter) 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: def _get_board(self) -> Board:
# Find the first board with a matching name # Find the first board with a matching name