phanikumv commented on code in PR #77139:
URL: https://github.com/apache/airflow/pull/77139#discussion_r4631106824


##########
providers/openai/src/airflow/providers/openai/hooks/openai.py:
##########
@@ -209,9 +215,14 @@ def get_conn(self) -> OpenAI:
         * ``"api_key"`` -- use the API key from the connection password (or 
``openai_client_kwargs``).
         * ``"workload_identity"`` -- exchange a short-lived identity token for 
API access using the
           OpenAI client's workload identity support. See 
:meth:`_build_workload_identity`.
+
+        :param async_client: Return an ``AsyncOpenAI`` instead, for sync code 
that passes one to
+            an async library. The connection lookup blocks, so in async code 
use :meth:`aget_conn`.
+            Each call builds a new client.

Review Comment:
   `run_durably_sync` goes through `run_coroutine_sync`, and that calls 
asyncio.run on each call, which makes a new loop each time. The client's httpx 
pool keeps connections from the first loop. 
   
   Thus, if a task makes the client once and calls run_durably_sync two times, 
the second call can fail with RuntimeError: Event loop is closed. See 
[encode/httpx#2959](https://github.com/encode/httpx/issues/2959) and 
[openai/openai-python#1254](https://github.com/openai/openai-python/issues/1254).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to