Vertex AI V1 API - Class Google::Cloud::AIPlatform::V1::PredictionService::Client (v0.35.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

#direct_predict

def direct_predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::DirectPredictResponse
def direct_predict(endpoint: nil, inputs: nil, parameters: nil) -> ::Google::Cloud::AIPlatform::V1::DirectPredictResponse

Perform an unary online prediction request for Vertex first-party products and frameworks.

Overloads
def direct_predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::DirectPredictResponse
Pass arguments to direct_predict via a request object, either of type DirectPredictRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::DirectPredictRequest, ::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 direct_predict(endpoint: nil, inputs: nil, parameters: nil) -> ::Google::Cloud::AIPlatform::V1::DirectPredictResponse
Pass arguments to direct_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
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::DirectPredictRequest.new

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

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

#direct_raw_predict

def direct_raw_predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::DirectRawPredictResponse
def direct_raw_predict(endpoint: nil, method_name: nil, input: nil) -> ::Google::Cloud::AIPlatform::V1::DirectRawPredictResponse

Perform an online prediction request through gRPC.

Overloads
def direct_raw_predict(request, options = nil) -> ::Google::Cloud::AIPlatform::V1::DirectRawPredictResponse
Pass arguments to direct_raw_predict via a request object, either of type DirectRawPredictRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::DirectRawPredictRequest, ::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 direct_raw_predict(endpoint: nil, method_name: nil, input: nil) -> ::Google::Cloud::AIPlatform::V1::DirectRawPredictResponse
Pass arguments to direct_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}
  • method_name (::String) — Fully qualified name of the API method being invoked to perform predictions.

    Format: /namespace.Service/Method/ Example: /tensorflow.serving.PredictionService/Predict

  • input (::String) — The prediction input.
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::DirectRawPredictRequest.new

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

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

#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

#server_streaming_predict

def server_streaming_predict(request, options = nil) -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingPredictResponse>
def server_streaming_predict(endpoint: nil, inputs: nil, parameters: nil) -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingPredictResponse>

Perform a server-side streaming online prediction request for Vertex LLM streaming.

Overloads
def server_streaming_predict(request, options = nil) -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingPredictResponse>
Pass arguments to server_streaming_predict via a request object, either of type StreamingPredictRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::AIPlatform::V1::StreamingPredictRequest, ::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 server_streaming_predict(endpoint: nil, inputs: nil, parameters: nil) -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingPredictResponse>
Pass arguments to server_streaming_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
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::StreamingPredictRequest.new

# Call the server_streaming_predict method to start streaming.
output = client.server_streaming_predict request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::AIPlatform::V1::StreamingPredictResponse
output.each do |current_response|
  p current_response
end

#streaming_predict

def streaming_predict(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingPredictResponse>

Perform a streaming online prediction request for Vertex first-party products and frameworks.

Parameters
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 an input stream.
input = Gapic::StreamInput.new

# Call the streaming_predict method to start streaming.
output = client.streaming_predict input

# Send requests on the stream. For each request object, set fields by
# passing keyword arguments. Be sure to close the stream when done.
input << Google::Cloud::AIPlatform::V1::StreamingPredictRequest.new
input << Google::Cloud::AIPlatform::V1::StreamingPredictRequest.new
input.close

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::AIPlatform::V1::StreamingPredictResponse
output.each do |current_response|
  p current_response
end

#streaming_raw_predict

def streaming_raw_predict(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::AIPlatform::V1::StreamingRawPredictResponse>

Perform a streaming online prediction request through gRPC.

Parameters
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 an input stream.
input = Gapic::StreamInput.new

# Call the streaming_raw_predict method to start streaming.
output = client.streaming_raw_predict input

# Send requests on the stream. For each request object, set fields by
# passing keyword arguments. Be sure to close the stream when done.
input << Google::Cloud::AIPlatform::V1::StreamingRawPredictRequest.new
input << Google::Cloud::AIPlatform::V1::StreamingRawPredictRequest.new
input.close

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::AIPlatform::V1::StreamingRawPredictResponse
output.each do |current_response|
  p current_response
end