feat: Add better error catching for files upload (#4145)

This commit is contained in:
Matthew Zhou
2025-08-24 16:46:57 -07:00
committed by GitHub
parent 7bd9be5a04
commit 2ceb144afb
5 changed files with 53 additions and 13 deletions

View File

@@ -286,17 +286,11 @@ def upload_file_and_wait(
file_path: str,
name: Optional[str] = None,
max_wait: int = 60,
duplicate_handling: Optional["DuplicateFileHandling"] = None,
duplicate_handling: Optional[str] = None,
):
"""Helper function to upload a file and wait for processing to complete"""
from letta_client import DuplicateFileHandling as ClientDuplicateFileHandling
with open(file_path, "rb") as f:
if duplicate_handling:
# handle both client and server enum types
if hasattr(duplicate_handling, "value"):
# server enum type
duplicate_handling = ClientDuplicateFileHandling(duplicate_handling.value)
file_metadata = client.sources.files.upload(source_id=source_id, file=f, duplicate_handling=duplicate_handling, name=name)
else:
file_metadata = client.sources.files.upload(source_id=source_id, file=f, name=name)