Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/huggingface_hub/inference/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,12 @@ def _format_chat_completion_stream_output(


async def _async_yield_from(client: "ClientSession", response: "ClientResponse") -> AsyncIterable[bytes]:
async for byte_payload in response.content:
yield byte_payload.strip()
await client.close()
try:
async for byte_payload in response.content:
yield byte_payload.strip()
finally:
# Always close the underlying HTTP session to avoid resource leaks
await client.close()


# "TGI servers" are servers running with the `text-generation-inference` backend.
Expand Down