|
12 | 12 |
|
13 | 13 | try: |
14 | 14 | from azure.ai.generative import AIClient |
15 | | - from azure.ai.generative.entities import Connection |
| 15 | + from azure.ai.generative.entities import BaseConnection |
16 | 16 | except Exception: |
17 | 17 | AIClient = None |
18 | | - Connection = None |
| 18 | + BaseConnection = None |
19 | 19 | try: |
20 | 20 | from azure.ai.ml import MLClient |
21 | 21 | from azure.ai.ml.entities import WorkspaceConnection |
@@ -84,12 +84,12 @@ def get_connection_credential(config, credential: Optional[TokenCredential] = No |
84 | 84 | return connection_credential |
85 | 85 |
|
86 | 86 |
|
87 | | -def workspace_connection_to_credential(connection: Union[dict, Connection, WorkspaceConnection]): |
| 87 | +def workspace_connection_to_credential(connection: Union[dict, BaseConnection, WorkspaceConnection]): |
88 | 88 | """Get a credential for a workspace connection.""" |
89 | 89 | return connection_to_credential(connection) |
90 | 90 |
|
91 | 91 |
|
92 | | -def connection_to_credential(connection: Union[dict, Connection, WorkspaceConnection]): |
| 92 | +def connection_to_credential(connection: Union[dict, BaseConnection, WorkspaceConnection]): |
93 | 93 | """Get a credential for a workspace connection.""" |
94 | 94 | if isinstance(connection, dict): |
95 | 95 | props = connection["properties"] |
@@ -145,7 +145,7 @@ def connection_to_credential(connection: Union[dict, Connection, WorkspaceConnec |
145 | 145 | raise ValueError(f"Unknown auth type '{connection.credentials.type}' for connection '{connection.name}'") |
146 | 146 |
|
147 | 147 |
|
148 | | -def get_connection_by_id_v2(connection_id: str, credential: TokenCredential = None, client: str = "sdk") -> Union[dict, WorkspaceConnection, Connection]: |
| 148 | +def get_connection_by_id_v2(connection_id: str, credential: TokenCredential = None, client: str = "sdk") -> Union[dict, WorkspaceConnection, BaseConnection]: |
149 | 149 | """ |
150 | 150 | Get a connection by id using azure.ai.ml or azure.ai.generative. |
151 | 151 |
|
@@ -204,37 +204,37 @@ def get_connection_by_id_v2(connection_id: str, credential: TokenCredential = No |
204 | 204 | return connection |
205 | 205 |
|
206 | 206 |
|
207 | | -def get_id_from_connection(connection: Union[dict, WorkspaceConnection, Connection]) -> str: |
| 207 | +def get_id_from_connection(connection: Union[dict, WorkspaceConnection, BaseConnection]) -> str: |
208 | 208 | """Get a connection id from a connection.""" |
209 | 209 | if isinstance(connection, dict): |
210 | 210 | return connection["id"] |
211 | 211 | elif isinstance(connection, WorkspaceConnection): |
212 | 212 | return connection.id |
213 | | - elif isinstance(connection, Connection): |
| 213 | + elif isinstance(connection, BaseConnection): |
214 | 214 | return connection.id |
215 | 215 | else: |
216 | 216 | raise ValueError(f"Unknown connection type: {type(connection)}") |
217 | 217 |
|
218 | 218 |
|
219 | | -def get_target_from_connection(connection: Union[dict, WorkspaceConnection, Connection]) -> str: |
| 219 | +def get_target_from_connection(connection: Union[dict, WorkspaceConnection, BaseConnection]) -> str: |
220 | 220 | """Get a connection target from a connection.""" |
221 | 221 | if isinstance(connection, dict): |
222 | 222 | return connection["properties"]["target"] |
223 | 223 | elif isinstance(connection, WorkspaceConnection): |
224 | 224 | return connection.target |
225 | | - elif isinstance(connection, Connection): |
| 225 | + elif isinstance(connection, BaseConnection): |
226 | 226 | return connection.target |
227 | 227 | else: |
228 | 228 | raise ValueError(f"Unknown connection type: {type(connection)}") |
229 | 229 |
|
230 | 230 |
|
231 | | -def get_metadata_from_connection(connection: Union[dict, WorkspaceConnection, Connection]) -> dict: |
| 231 | +def get_metadata_from_connection(connection: Union[dict, WorkspaceConnection, BaseConnection]) -> dict: |
232 | 232 | """Get a connection metadata from a connection.""" |
233 | 233 | if isinstance(connection, dict): |
234 | 234 | return connection["properties"]["metadata"] |
235 | 235 | elif isinstance(connection, WorkspaceConnection): |
236 | 236 | return connection.metadata |
237 | | - elif isinstance(connection, Connection): |
| 237 | + elif isinstance(connection, BaseConnection): |
238 | 238 | return connection.metadata |
239 | 239 | else: |
240 | 240 | raise ValueError(f"Unknown connection type: {type(connection)}") |
|
0 commit comments