Skip to content

Commit

Permalink
Conditionally set source_path_size in the loaders and docs. (langchai…
Browse files Browse the repository at this point in the history
…n-ai#14)

Handle no source path in get_source_size.
  • Loading branch information
Raj725 authored Jan 30, 2024
1 parent 27846f4 commit 1d807cc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions libs/community/langchain_community/document_loaders/pebblo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def __init__(
"loader": loader_name,
"source_path": self.source_path,
"source_type": self.source_type,
"source_path_size": self.source_path_size,
**(
{"source_path_size": self.source_path_size}
if self.source_path_size is not None
else {}
),
}
# generate app
self.app = self._get_app_details()
Expand Down Expand Up @@ -109,7 +113,11 @@ def _send_loader_doc(self, loading_end=False):
"source_path": doc_source_path,
"last_modified": doc.get("metadata", {}).get("last_modified"),
"file_owner": doc_source_owner,
"source_path_size": doc_source_size,
**(
{"source_path_size": doc_source_size}
if doc_source_size is not None
else {}
),
}
)
payload = {
Expand Down Expand Up @@ -226,7 +234,9 @@ def get_file_owner_from_path(file_path: str) -> str:
return file_owner_name

def get_source_size(self, source_path: str) -> int:
size = 0
if not source_path:
return None
size = None
if os.path.isfile(source_path):
size = os.path.getsize(source_path)
elif os.path.isdir(source_path):
Expand Down

0 comments on commit 1d807cc

Please sign in to comment.