fix: NotRequired for file_size TypedDict field; defensive seek(0) before file_data

This commit is contained in:
Ishaan Jaffer 2026-03-23 11:56:27 -07:00
parent cc6406f16c
commit 1f38a63e3f
2 changed files with 6 additions and 2 deletions

View file

@ -446,6 +446,10 @@ async def create_file( # noqa: PLR0915
# Pass file.file (the underlying SpooledTemporaryFile / BytesIO) rather than
# reading all bytes into memory — the IO object is fully compatible with
# FileTypes and lets downstream providers stream the upload.
# Ensure pointer is at 0 before any code reads from file.file, so that
# subsequent seek-based operations (file_size, JSONL sniff, upload) start
# from the beginning of the file regardless of prior reads.
file.file.seek(0)
file_data = (file.filename, file.file, file.content_type)
## check if model is a loadbalanced model

View file

@ -41,7 +41,7 @@ from pydantic import (
field_validator,
model_validator,
)
from typing_extensions import Required, TypedDict
from typing_extensions import NotRequired, Required, TypedDict
from litellm._uuid import uuid
from litellm.types.llms.base import (
@ -3494,7 +3494,7 @@ class ExtractedFileData(TypedDict):
content: Union[bytes, "IO[bytes]"]
content_type: Optional[str]
headers: Mapping[str, str]
file_size: Optional[int]
file_size: NotRequired[Optional[int]]
class SpecialEnums(Enum):