File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,9 @@ async def stream(
378378
379379 logger .debug ("invoking model" )
380380
381+ # We initialize an OpenAI context on every request so as to avoid connection sharing in the underlying httpx
382+ # client. The asyncio event loop does not allow connections to be shared. For more details, please refer to
383+ # https://github.com/encode/httpx/discussions/2959.
381384 async with openai .AsyncOpenAI (** self .client_args ) as client :
382385 response = await client .chat .completions .create (** request )
383386
@@ -449,6 +452,9 @@ async def structured_output(
449452 Yields:
450453 Model events with the last being the structured output.
451454 """
455+ # We initialize an OpenAI context on every request so as to avoid connection sharing in the underlying httpx
456+ # client. The asyncio event loop does not allow connections to be shared. For more details, please refer to
457+ # https://github.com/encode/httpx/discussions/2959.
452458 async with openai .AsyncOpenAI (** self .client_args ) as client :
453459 response : ParsedChatCompletion = await client .beta .chat .completions .parse (
454460 model = self .get_config ()["model_id" ],
You can’t perform that action at this time.
0 commit comments