pankajkoti commented on code in PR #36014:
URL: https://github.com/apache/airflow/pull/36014#discussion_r1415564837


##########
airflow/providers/openai/hooks/openai.py:
##########
@@ -57,21 +54,25 @@ def get_ui_field_behaviour() -> dict[str, Any]:
 
     def test_connection(self) -> tuple[bool, str]:
         try:
-            openai.Model.list()
+            self.conn.models.list()
             return True, "Connection established!"
         except Exception as e:
             return False, str(e)
 
-    def _get_api_key(self) -> str:
-        """Get the OpenAI API key from the connection."""
-        conn = self.get_connection(self.conn_id)
-        if not conn.password:
-            raise ValueError("OpenAI API key not found in connection")
-        return str(conn.password)
+    @cached_property
+    def conn(self) -> OpenAI:
+        """Return an OpenAI connection object."""
+        return self.get_conn()
 
-    def _get_api_base(self) -> None | str:
+    def get_conn(self) -> OpenAI:
+        """Return an OpenAI connection object."""
         conn = self.get_connection(self.conn_id)
-        return conn.host
+        url = conn.host or None
+        password = conn.password
+        return OpenAI(
+            api_key=password,
+            base_url=url,
+        )

Review Comment:
   Thanks. Accepting those as extras kawrgs so that we don't have to keep 
updating the kwargs as the client changes across versions.
   
   Updated the connections doc with an example for the same.



-- 
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