Skip to content

Commit

Permalink
chore: update dev with changes to master (googleapis#33)
Browse files Browse the repository at this point in the history
* Export aiplatform_v1beta1 as aiplatform.gapic_v1beta1 (googleapis#17)

Freeing up the google.cloud.aiplatform namespace for MB SDK

* GAPIC namespace (googleapis#20)

* name space google.cloud.aiplatform.gapic

* Init Disclaimer (googleapis#28)

* clean up docstrings that are not rendered properly in reference doc (googleapis#24)

Co-authored-by: Vinny Senthil <[email protected]>

* fix: re-add py sessions to noxfile (googleapis#22)

* fix: re-add py sessions to noxfile

Co-authored-by: Vinny Senthil <[email protected]>

Co-authored-by: Yu-Han Liu <[email protected]>
Co-authored-by: Vinny Senthil <[email protected]>
  • Loading branch information
3 people committed Nov 30, 2020
1 parent 8e50f3b commit 83b2b9a
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 2,192 deletions.
14 changes: 10 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Python Client for Cloud AI Platform
|beta| |pypi| |versions|


`Cloud AI Platform`_: Google Cloud AI Platform is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It offers both novices and experts the best workbench for the entire machine learning development lifecycle.
:Warning: This library is a pre-release product and is subject to breaking changes.

`Cloud AI Platform`_: Cloud AI Platform is a suite of machine learning tools that enables
developers to train high-quality models specific to their business needs.
It offers both novices and experts the best workbench for machine learning
development by leveraging Google's state-of-the-art transfer learning and
Neural Architecture Search technology.

- `Client Library Documentation`_
- `Product Documentation`_
Expand All @@ -15,9 +21,9 @@ Python Client for Cloud AI Platform
:target: https://pypi.org/project/google-cloud-aiplatform/
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-aiplatform.svg
:target: https://pypi.org/project/google-cloud-aiplatform/
.. _Cloud AI Platform: https://cloud.google.com/ai-platform-unified/docs
.. _Cloud AI Platform: https://cloud.google.com/ai-platform/docs
.. _Client Library Documentation: https://googleapis.dev/python/aiplatform/latest
.. _Product Documentation: https://cloud.google.com/ai-platform-unified/docs
.. _Product Documentation: https://cloud.google.com/ai-platform/docs

Quick Start
-----------
Expand Down Expand Up @@ -79,5 +85,5 @@ Next Steps
- View this `README`_ to see the full list of Cloud
APIs that we cover.

.. _Cloud AI Platform API Product documentation: https://cloud.google.com/ai-platform-unified/docs
.. _Cloud AI Platform API Product documentation: https://cloud.google.com/ai-platform/docs
.. _README: https://github.com/googleapis/google-cloud-python/blob/master/README.rst
877 changes: 247 additions & 630 deletions google/cloud/aiplatform_v1beta1/services/job_service/client.py

Large diffs are not rendered by default.

386 changes: 70 additions & 316 deletions google/cloud/aiplatform_v1beta1/services/pipeline_service/client.py

Large diffs are not rendered by default.

313 changes: 46 additions & 267 deletions google/cloud/aiplatform_v1beta1/services/prediction_service/client.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@
# limitations under the License.
#

import warnings
from typing import Callable, Dict, Optional, Sequence, Tuple
from typing import Callable, Dict

from google.api_core import grpc_helpers # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google import auth # type: ignore
from google.auth import credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore

import grpc # type: ignore

from google.cloud.aiplatform_v1beta1.types import prediction_service

from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO
from .base import PredictionServiceTransport


class PredictionServiceGrpcTransport(PredictionServiceTransport):
Expand All @@ -44,21 +40,12 @@ class PredictionServiceGrpcTransport(PredictionServiceTransport):
top of HTTP/2); the ``grpcio`` package must be installed.
"""

_stubs: Dict[str, Callable]

def __init__(
self,
*,
host: str = "aiplatform.googleapis.com",
credentials: credentials.Credentials = None,
credentials_file: str = None,
scopes: Sequence[str] = None,
channel: grpc.Channel = None,
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
ssl_channel_credentials: grpc.ChannelCredentials = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
channel: grpc.Channel = None
) -> None:
"""Instantiate the transport.
Expand All @@ -70,123 +57,28 @@ def __init__(
are specified, the client will attempt to ascertain the
credentials from the environment.
This argument is ignored if ``channel`` is provided.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is ignored if ``channel`` is provided.
scopes (Optional(Sequence[str])): A list of scopes. This argument is
ignored if ``channel`` is provided.
channel (Optional[grpc.Channel]): A ``Channel`` instance through
which to make calls.
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
If provided, it overrides the ``host`` argument and tries to create
a mutual TLS channel with client SSL credentials from
``client_cert_source`` or applicatin default SSL credentials.
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
Deprecated. A callback to provide client SSL certificate bytes and
private key bytes, both in PEM format. It is ignored if
``api_mtls_endpoint`` is None.
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
for grpc channel. It is ignored if ``channel`` is provided.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
creation failed for any reason.
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

# Sanity check: Ensure that channel and credentials are not both
# provided.
if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
DeprecationWarning,
)

host = (
api_mtls_endpoint
if ":" in api_mtls_endpoint
else api_mtls_endpoint + ":443"
)

if credentials is None:
credentials, _ = auth.default(
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
)

# Create SSL credentials with client_cert_source or application
# default SSL credentials.
if client_cert_source:
cert, key = client_cert_source()
ssl_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
else:
ssl_credentials = SslCredentials().ssl_credentials

# create a new channel. The provided one is ignored.
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

if credentials is None:
credentials, _ = auth.default(
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
)

# create a new channel. The provided one is ignored.
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
ssl_credentials=ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)

# Run the base constructor.
super().__init__(host=host, credentials=credentials)
self._stubs = {} # type: Dict[str, Callable]

# Run the base constructor.
super().__init__(
host=host,
credentials=credentials,
credentials_file=credentials_file,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
client_info=client_info,
)
# If a channel was explicitly provided, set it.
if channel:
self._grpc_channel = channel

@classmethod
def create_channel(
cls,
host: str = "aiplatform.googleapis.com",
credentials: credentials.Credentials = None,
credentials_file: str = None,
scopes: Optional[Sequence[str]] = None,
quota_project_id: Optional[str] = None,
**kwargs,
**kwargs
) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
Expand All @@ -196,37 +88,30 @@ def create_channel(
credentials identify this application to the service. If
none are specified, the client will attempt to ascertain
the credentials from the environment.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is mutually exclusive with credentials.
scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
service. These are only used when credentials are not specified and
are passed to :func:`google.auth.default`.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
kwargs (Optional[dict]): Keyword arguments, which are passed to the
channel creation.
Returns:
grpc.Channel: A gRPC channel object.
Raises:
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
scopes = scopes or cls.AUTH_SCOPES
return grpc_helpers.create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
scopes=scopes,
quota_project_id=quota_project_id,
**kwargs,
host, credentials=credentials, scopes=cls.AUTH_SCOPES, **kwargs
)

@property
def grpc_channel(self) -> grpc.Channel:
"""Return the channel designed to connect to this service.
"""Create the channel designed to connect to this service.
This property caches on the instance; repeated calls return
the same channel.
"""
# Sanity check: Only create a new channel if we do not already
# have one.
if not hasattr(self, "_grpc_channel"):
self._grpc_channel = self.create_channel(
self._host, credentials=self._credentials,
)

# Return the channel from cache.
return self._grpc_channel

@property
Expand Down Expand Up @@ -267,13 +152,11 @@ def explain(
Perform an online explanation.
If
``deployed_model_id``
is specified, the corresponding DeployModel must have
If [ExplainRequest.deployed_model_id] is specified, the
corresponding DeployModel must have
``explanation_spec``
populated. If
``deployed_model_id``
is not specified, all DeployedModels must have
populated. If [ExplainRequest.deployed_model_id] is not
specified, all DeployedModels must have
``explanation_spec``
populated. Only deployed AutoML tabular Models have
explanation_spec.
Expand Down
Loading

0 comments on commit 83b2b9a

Please sign in to comment.