Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/mistralai/utils/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def is_nullable(field):
if origin is Nullable or origin is OptionalNullable:
return True

if not origin is Union or type(None) not in get_args(field):
if origin is not Union or type(None) not in get_args(field):
return False

for arg in get_args(field):
Expand All @@ -202,7 +202,11 @@ def stream_to_text(stream: httpx.Response) -> str:


async def stream_to_text_async(stream: httpx.Response) -> str:
return "".join([chunk async for chunk in stream.aiter_text()])
# Use buffered accumulation for improved memory efficiency on large responses
buffer = []
async for chunk in stream.aiter_text():
buffer.append(chunk)
return "".join(buffer)


def stream_to_bytes(stream: httpx.Response) -> bytes:
Expand Down
2 changes: 2 additions & 0 deletions src/mistralai/utils/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def match_status_codes(status_codes: List[str], status_code: int) -> bool:

T = TypeVar("T")


def cast_partial(typ):
return partial(cast, typ)


def get_global_from_env(
value: Optional[T], env_key: str, type_cast: Callable[[str], T]
) -> Optional[T]:
Expand Down