|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) Python Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | + |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, TYPE_CHECKING, Union |
| 11 | +from typing_extensions import Self |
| 12 | + |
| 13 | +from azure.core import PipelineClient |
| 14 | +from azure.core.credentials import AzureKeyCredential |
| 15 | +from azure.core.pipeline import policies |
| 16 | +from azure.core.rest import HttpRequest, HttpResponse |
| 17 | + |
| 18 | +from ._configuration import AIProjectClientConfiguration |
| 19 | +from ._serialization import Deserializer, Serializer |
| 20 | +from .operations import ( |
| 21 | + ConnectionsOperations, |
| 22 | + DatasetsOperations, |
| 23 | + DeploymentsOperations, |
| 24 | + EvaluationsOperations, |
| 25 | + IndexesOperations, |
| 26 | + InternalOperations, |
| 27 | + RedTeamsOperations, |
| 28 | + ServicePatternsOperations, |
| 29 | +) |
| 30 | + |
| 31 | +if TYPE_CHECKING: |
| 32 | + from azure.core.credentials import TokenCredential |
| 33 | + |
| 34 | + |
| 35 | +class AIProjectClient: # pylint: disable=too-many-instance-attributes |
| 36 | + """AIProjectClient. |
| 37 | +
|
| 38 | + :ivar internal: InternalOperations operations |
| 39 | + :vartype internal: azure.ai.projects.onedp.operations.InternalOperations |
| 40 | + :ivar service_patterns: ServicePatternsOperations operations |
| 41 | + :vartype service_patterns: azure.ai.projects.onedp.operations.ServicePatternsOperations |
| 42 | + :ivar connections: ConnectionsOperations operations |
| 43 | + :vartype connections: azure.ai.projects.onedp.operations.ConnectionsOperations |
| 44 | + :ivar evaluations: EvaluationsOperations operations |
| 45 | + :vartype evaluations: azure.ai.projects.onedp.operations.EvaluationsOperations |
| 46 | + :ivar datasets: DatasetsOperations operations |
| 47 | + :vartype datasets: azure.ai.projects.onedp.operations.DatasetsOperations |
| 48 | + :ivar indexes: IndexesOperations operations |
| 49 | + :vartype indexes: azure.ai.projects.onedp.operations.IndexesOperations |
| 50 | + :ivar deployments: DeploymentsOperations operations |
| 51 | + :vartype deployments: azure.ai.projects.onedp.operations.DeploymentsOperations |
| 52 | + :ivar red_teams: RedTeamsOperations operations |
| 53 | + :vartype red_teams: azure.ai.projects.onedp.operations.RedTeamsOperations |
| 54 | + :param endpoint: Project endpoint. In the form |
| 55 | + "https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/_project" |
| 56 | + if your Foundry Hub has only one Project, or to use the default Project in your Hub. Or in the |
| 57 | + form |
| 58 | + "https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/<your-project-name>" |
| 59 | + if you want to explicitly |
| 60 | + specify the Foundry Project name. Required. |
| 61 | + :type endpoint: str |
| 62 | + :param credential: Credential used to authenticate requests to the service. Is either a key |
| 63 | + credential type or a token credential type. Required. |
| 64 | + :type credential: ~azure.core.credentials.AzureKeyCredential or |
| 65 | + ~azure.core.credentials.TokenCredential |
| 66 | + :keyword api_version: The API version to use for this operation. Default value is |
| 67 | + "2025-05-15-preview". Note that overriding this default value may result in unsupported |
| 68 | + behavior. |
| 69 | + :paramtype api_version: str |
| 70 | + """ |
| 71 | + |
| 72 | + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: |
| 73 | + _endpoint = "{endpoint}" |
| 74 | + self._config = AIProjectClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) |
| 75 | + |
| 76 | + _policies = kwargs.pop("policies", None) |
| 77 | + if _policies is None: |
| 78 | + _policies = [ |
| 79 | + policies.RequestIdPolicy(**kwargs), |
| 80 | + self._config.headers_policy, |
| 81 | + self._config.user_agent_policy, |
| 82 | + self._config.proxy_policy, |
| 83 | + policies.ContentDecodePolicy(**kwargs), |
| 84 | + self._config.redirect_policy, |
| 85 | + self._config.retry_policy, |
| 86 | + self._config.authentication_policy, |
| 87 | + self._config.custom_hook_policy, |
| 88 | + self._config.logging_policy, |
| 89 | + policies.DistributedTracingPolicy(**kwargs), |
| 90 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 91 | + self._config.http_logging_policy, |
| 92 | + ] |
| 93 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) |
| 94 | + |
| 95 | + self._serialize = Serializer() |
| 96 | + self._deserialize = Deserializer() |
| 97 | + self._serialize.client_side_validation = False |
| 98 | + self.internal = InternalOperations(self._client, self._config, self._serialize, self._deserialize) |
| 99 | + self.service_patterns = ServicePatternsOperations( |
| 100 | + self._client, self._config, self._serialize, self._deserialize |
| 101 | + ) |
| 102 | + self.connections = ConnectionsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 103 | + self.evaluations = EvaluationsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 104 | + self.datasets = DatasetsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 105 | + self.indexes = IndexesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 106 | + self.deployments = DeploymentsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 107 | + self.red_teams = RedTeamsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 108 | + |
| 109 | + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 110 | + """Runs the network request through the client's chained policies. |
| 111 | +
|
| 112 | + >>> from azure.core.rest import HttpRequest |
| 113 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 114 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 115 | + >>> response = client.send_request(request) |
| 116 | + <HttpResponse: 200 OK> |
| 117 | +
|
| 118 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 119 | +
|
| 120 | + :param request: The network request you want to make. Required. |
| 121 | + :type request: ~azure.core.rest.HttpRequest |
| 122 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 123 | + :return: The response of your network call. Does not do error handling on your response. |
| 124 | + :rtype: ~azure.core.rest.HttpResponse |
| 125 | + """ |
| 126 | + |
| 127 | + request_copy = deepcopy(request) |
| 128 | + path_format_arguments = { |
| 129 | + "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), |
| 130 | + } |
| 131 | + |
| 132 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 133 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 134 | + |
| 135 | + def close(self) -> None: |
| 136 | + self._client.close() |
| 137 | + |
| 138 | + def __enter__(self) -> Self: |
| 139 | + self._client.__enter__() |
| 140 | + return self |
| 141 | + |
| 142 | + def __exit__(self, *exc_details: Any) -> None: |
| 143 | + self._client.__exit__(*exc_details) |
0 commit comments