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
When I use FastAPI for forwarding and set stream=True, for example: async for res in await openai.ChatCompletion.acreate(**kwargs), when this request is terminated before it completes, an exception occurs as follows: [asyncio] [ERROR]: Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f0ca458c490>.
To Reproduce
1. Write a FastAPI request using the acreate method to return data in streaming format.
2. Use a packet sending tool to make a request to the written API, terminate the request while receiving data.
3. Wait for a moment, and the exception will be displayed in the terminal.
Code snippets
No response
OS
Linux
Python version
Python 3.11.4
Library version
openai 0.27.8
### Tasks
The text was updated successfully, but these errors were encountered:
This is likely fixed in our upcoming v1 beta as we've moved to an explicit client instance based API which makes controlling the HTTP instances much easier.
fromopenaiimportOpenAIclient=OpenAI()
# make requestsclient.close() # close manually# or using a context managerwithOpenAI() asclient:
# make requests
...
It should be noted that we highly recommend using one client instance and re-using it between requests as we can then re-use HTTP connections leading to a massive performance boost.
Describe the bug
When I use FastAPI for forwarding and set stream=True, for example: async for res in await openai.ChatCompletion.acreate(**kwargs), when this request is terminated before it completes, an exception occurs as follows: [asyncio] [ERROR]: Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f0ca458c490>.
To Reproduce
Code snippets
No response
OS
Linux
Python version
Python 3.11.4
Library version
openai 0.27.8
The text was updated successfully, but these errors were encountered: