Vertex AI V1 API - Class Google::Cloud::AIPlatform::V1::PredictionService::Client (v0.26.0)

Reference documentation and code samples for the Vertex AI V1 API class Google::Cloud::AIPlatform::V1::PredictionService::Client.

Client for the PredictionService service.

A service for online predictions and explanations.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the PredictionService Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all PredictionService clients
::Google::Cloud::AIPlatform::V1::PredictionService::Client.configure do |config|
  config.timeout = 10.0
end

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the PredictionService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#explain

def explain(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::ExplainResponse
def explain(endpoint: nil, instances: nil, parameters: nil, explanation_spec_override: nil, deployed_model_id: nil) -> ::Google::Cloud::AIPlatform::V1::ExplainResponse

Perform an online explanation.

If deployed_model_id is specified, the corresponding DeployModel must have explanation_spec populated. If deployed_model_id is not specified, all DeployedModels must have explanation_spec populated.

Overloads
def explain(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::ExplainResponse
Pass arguments to explain via a request object, either of type ExplainRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::ExplainRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def explain(endpoint: nil, instances: nil, parameters: nil, explanation_spec_override: nil, deployed_model_id: nil) -> ::Google::Cloud::AIPlatform::V1::ExplainResponse
Pass arguments to explain via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • endpoint (::String) — Required. The name of the Endpoint requested to serve the explanation. Format: projects/{project}/locations/{location}/endpoints/{endpoint}
  • instances (::Array<::Google::Protobuf::Value, ::Hash>) — Required. The instances that are the input to the explanation call. A DeployedModel may have an upper limit on the number of instances it supports per request, and when it is exceeded the explanation call errors in case of AutoML Models, or, in case of customer created Models, the behaviour is as documented by that Model. The schema of any single instance may be specified via Endpoint's DeployedModels' [Model's][google.cloud.aiplatform.v1.DeployedModel.model] [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] instance_schema_uri.
  • parameters (::Google::Protobuf::Value, ::Hash) — The parameters that govern the prediction. The schema of the parameters may be specified via Endpoint's DeployedModels' [Model's ][google.cloud.aiplatform.v1.DeployedModel.model] [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] parameters_schema_uri.
  • explanation_spec_override (::Google::Cloud::AIPlatform::V1::ExplanationSpecOverride, ::Hash) —

    If specified, overrides the explanation_spec of the DeployedModel. Can be used for explaining prediction results with different configurations, such as:

    • Explaining top-5 predictions results as opposed to top-1;
    • Increasing path count or step count of the attribution methods to reduce approximate errors;
    • Using different baselines for explaining the prediction results.
  • deployed_model_id (::String) — If specified, this ExplainRequest will be served by the chosen DeployedModel, overriding Endpoint.traffic_split.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/ai_platform/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::AIPlatform::V1::PredictionService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::AIPlatform::V1::ExplainRequest.new

# Call the explain method.
result = client.explain request

# The returned object is of type Google::Cloud::AIPlatform::V1::ExplainResponse.
p result

#iam_policy_client

def iam_policy_client() -> Google::Iam::V1::IAMPolicy::Client

Get the associated client for mix-in of the IAMPolicy.

Returns
  • (Google::Iam::V1::IAMPolicy::Client)

#initialize

def initialize() { |config| ... } -> Client

Create a new PredictionService client object.

Yields
  • (config) — Configure the PredictionService client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::AIPlatform::V1::PredictionService::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::AIPlatform::V1::PredictionService::Client.new do |config|
  config.timeout = 10.0
end

#location_client

def location_client() -> Google::Cloud::Location::Locations::Client

Get the associated client for mix-in of the Locations.

Returns
  • (Google::Cloud::Location::Locations::Client)

#predict

def predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::PredictResponse
def predict(endpoint: nil, instances: nil, parameters: nil) -> ::Google::Cloud::AIPlatform::V1::PredictResponse

Perform an online prediction.

Overloads
def predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::PredictResponse
Pass arguments to predict via a request object, either of type Google::Cloud::AIPlatform::V1::PredictRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::PredictRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def predict(endpoint: nil, instances: nil, parameters: nil) -> ::Google::Cloud::AIPlatform::V1::PredictResponse
Pass arguments to predict via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • endpoint (::String) — Required. The name of the Endpoint requested to serve the prediction. Format: projects/{project}/locations/{location}/endpoints/{endpoint}
  • instances (::Array<::Google::Protobuf::Value, ::Hash>) — Required. The instances that are the input to the prediction call. A DeployedModel may have an upper limit on the number of instances it supports per request, and when it is exceeded the prediction call errors in case of AutoML Models, or, in case of customer created Models, the behaviour is as documented by that Model. The schema of any single instance may be specified via Endpoint's DeployedModels' [Model's][google.cloud.aiplatform.v1.DeployedModel.model] [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] instance_schema_uri.
  • parameters (::Google::Protobuf::Value, ::Hash) — The parameters that govern the prediction. The schema of the parameters may be specified via Endpoint's DeployedModels' [Model's ][google.cloud.aiplatform.v1.DeployedModel.model] [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] parameters_schema_uri.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/ai_platform/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::AIPlatform::V1::PredictionService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::AIPlatform::V1::PredictRequest.new

# Call the predict method.
result = client.predict request

# The returned object is of type Google::Cloud::AIPlatform::V1::PredictResponse.
p result

#raw_predict

def raw_predict(request, options = nil) -> ::Google::Api::HttpBody
def raw_predict(endpoint: nil, http_body: nil) -> ::Google::Api::HttpBody

Perform an online prediction with an arbitrary HTTP payload.

The response includes the following HTTP headers:

  • X-Vertex-AI-Endpoint-Id: ID of the Endpoint that served this prediction.

  • X-Vertex-AI-Deployed-Model-Id: ID of the Endpoint's DeployedModel that served this prediction.

Overloads
def raw_predict(request, options = nil) -> ::Google::Api::HttpBody
Pass arguments to raw_predict via a request object, either of type RawPredictRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::RawPredictRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def raw_predict(endpoint: nil, http_body: nil) -> ::Google::Api::HttpBody
Pass arguments to raw_predict via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • endpoint (::String) — Required. The name of the Endpoint requested to serve the prediction. Format: projects/{project}/locations/{location}/endpoints/{endpoint}
  • http_body (::Google::Api::HttpBody, ::Hash) — The prediction input. Supports HTTP headers and arbitrary data payload.

    A DeployedModel may have an upper limit on the number of instances it supports per request. When this limit it is exceeded for an AutoML model, the RawPredict method returns an error. When this limit is exceeded for a custom-trained model, the behavior varies depending on the model.

    You can specify the schema for each instance in the predict_schemata.instance_schema_uri field when you create a Model. This schema applies when you deploy the Model as a DeployedModel to an Endpoint and use the RawPredict method.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/ai_platform/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::AIPlatform::V1::PredictionService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::AIPlatform::V1::RawPredictRequest.new

# Call the raw_predict method.
result = client.raw_predict request

# The returned object is of type Google::Api::HttpBody.
p result