You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several fixes to make Completion.acreate(stream=True) work (#172)
* Added a failing test case for async completion stream
* Consume async generator with async for
* Consume the stream in chunks as sent by API, to avoid "empty" parts
The api will send chunks like
```
b'data: {"id": "cmpl-6W18L0k1kFoHUoSsJOwcPq7DKBaGX", "object": "text_completion", "created": 1673088873, "choices": [{"text": "_", "index": 0, "logprobs": null, "finish_reason": null}], "model": "ada"}\n\n'
```
The default iterator will break on each `\n` character, whereas iter_chunks will just output parts as they arrive
* Add another test using global aiosession
* Manually consume aiohttp_session asyncontextmanager to ensure that session is only closed once the response stream is finished
Previously we'd exit the with statement before the response stream is consumed by the caller, therefore, unless we're using a global ClientSession, the session is closed (and thus the request) before it should be.
* Ensure we close the session even if the caller raises an exception while consuming the stream
0 commit comments