Repository navigation
chore(ai_platform): add PredictionService and V1 acceptance smoke tests #36728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
torreypayne
wants to merge
1
commit into
main
Choose a base branch
from
chore/ai-platform-smoke-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+217
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
...cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require_relative "../../../../helper" | ||
|
|
||
| class PredictionServiceSmokeTest < Minitest::Test | ||
| GENERATE_MODEL = "gemini-3.1-flash-lite" | ||
| GENERATE_LOCATION = "global" | ||
| EMBED_MODEL = "gemini-embedding-001" | ||
| EMBED_LOCATION = "us-central1" | ||
|
|
||
| [:grpc, :rest].each do |transport| | ||
| define_method "test_generate_content_#{transport}" do | ||
| verify_generate_content transport | ||
| end | ||
|
|
||
| define_method "test_stream_generate_content_#{transport}" do | ||
| verify_stream_generate_content transport | ||
| end | ||
|
|
||
| define_method "test_embed_content_#{transport}" do | ||
| verify_embed_content transport | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def verify_generate_content transport | ||
| client = AcceptanceHelper.client :prediction_service, location: GENERATE_LOCATION, transport: transport | ||
| model = client.endpoint_path( | ||
| project: AcceptanceHelper.project_id, | ||
| location: GENERATE_LOCATION, | ||
| publisher: "google", | ||
| model: GENERATE_MODEL | ||
| ) | ||
|
|
||
| response = client.generate_content( | ||
| model: model, | ||
| contents: [{ role: "user", parts: [{ text: "Reply with the single word: pong" }] }], | ||
| generation_config: { max_output_tokens: 256 } | ||
| ) | ||
|
|
||
| refute_empty response.candidates | ||
| text = extract_text [response] | ||
| refute_empty text.strip | ||
| end | ||
|
|
||
| def verify_stream_generate_content transport | ||
| client = AcceptanceHelper.client :prediction_service, location: GENERATE_LOCATION, transport: transport | ||
| model = client.endpoint_path( | ||
| project: AcceptanceHelper.project_id, | ||
| location: GENERATE_LOCATION, | ||
| publisher: "google", | ||
| model: GENERATE_MODEL | ||
| ) | ||
|
|
||
| chunks = client.stream_generate_content( | ||
| model: model, | ||
| contents: [{ role: "user", parts: [{ text: "Reply with the single word: ok" }] }], | ||
| generation_config: { max_output_tokens: 256 } | ||
| ).to_a | ||
|
|
||
| refute_empty chunks | ||
| text = extract_text chunks | ||
| refute_empty text.strip | ||
| end | ||
|
|
||
| def verify_embed_content transport | ||
| client = AcceptanceHelper.client :prediction_service, location: EMBED_LOCATION, transport: transport | ||
| model = client.endpoint_path( | ||
| project: AcceptanceHelper.project_id, | ||
| location: EMBED_LOCATION, | ||
| publisher: "google", | ||
| model: EMBED_MODEL | ||
| ) | ||
|
|
||
| response = client.embed_content( | ||
| model: model, | ||
| content: { parts: [{ text: "Hello, world!" }] } | ||
| ) | ||
|
|
||
| refute_nil response.embedding | ||
| refute_empty response.embedding.values | ||
| end | ||
|
|
||
| def extract_text responses | ||
| responses.flat_map do |response| | ||
| response.candidates.flat_map do |candidate| | ||
| candidate.content&.parts&.filter_map(&:text) || [] | ||
| end | ||
| end.join | ||
| end | ||
| end | ||
45 changes: 45 additions & 0 deletions
45
google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/smoke_test.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require_relative "../../../../helper" | ||
|
|
||
| class SmokeTest < Minitest::Test | ||
| SMOKE_LOCATION = "us-east1" | ||
|
|
||
| SMOKE_CASES = [ | ||
| [:dataset_service, :list_datasets], | ||
| [:endpoint_service, :list_endpoints], | ||
| [:job_service, :list_batch_prediction_jobs], | ||
| [:job_service, :list_custom_jobs], | ||
| [:job_service, :list_hyperparameter_tuning_jobs], | ||
| [:migration_service, :search_migratable_resources], | ||
| [:model_service, :list_models], | ||
| [:pipeline_service, :list_training_pipelines] | ||
| ].freeze | ||
|
|
||
| SMOKE_CASES.each do |service, rpc| | ||
| [:grpc, :rest].each do |transport| | ||
| define_method "test_#{service}_#{rpc}_#{transport}" do | ||
| client = AcceptanceHelper.client service, location: SMOKE_LOCATION, transport: transport | ||
| parent = "projects/#{AcceptanceHelper.project_id}/locations/#{SMOKE_LOCATION}" | ||
| response = client.public_send rpc, parent: parent, page_size: 1 | ||
| expected_class = transport == :rest ? Gapic::Rest::PagedEnumerable : Gapic::PagedEnumerable | ||
| assert_kind_of expected_class, response | ||
| refute_nil response.response | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| if ENV["CI"] || ENV["KOKORO_JOB_NAME"] | ||
| # Load JUnit XML formatter from googleapis/ruby-common-tools for Kokoro/Sponge. | ||
| begin | ||
| require "gapic/minitest_junit_preloader" | ||
| rescue LoadError | ||
| # Ignored for local runs without ruby-common-tools on $LOAD_PATH. | ||
| end | ||
| end | ||
|
|
||
| require "minitest/autorun" | ||
| require "minitest/focus" | ||
| require "minitest/rg" | ||
|
|
||
| require "google/cloud/ai_platform" | ||
|
|
||
| ## | ||
| # Shared helpers for google-cloud-ai_platform acceptance smoke tests. | ||
| # | ||
| module AcceptanceHelper | ||
| ## | ||
| # Returns the GCP project ID configured for acceptance tests. | ||
| # | ||
| # @return [String] | ||
| # | ||
| def self.project_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason this is included at the service level? |
||
| ENV["GOOGLE_CLOUD_PROJECT"] || | ||
| ENV["GOOGLE_CLOUD_TEST_PROJECT"] || | ||
| ENV["GCLOUD_TEST_PROJECT"] || | ||
| raise("missing GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_TEST_PROJECT, or GCLOUD_TEST_PROJECT") | ||
| end | ||
|
|
||
| ## | ||
| # Instantiates a versioned AIPlatform service client for the given location and transport. | ||
| # | ||
| # @param service [Symbol] Factory method name on {Google::Cloud::AIPlatform}. | ||
| # @param location [String] Vertex AI location (e.g. "global", "us-central1", "us-east1"). | ||
| # @param transport [Symbol] RPC transport (`:grpc` or `:rest`). | ||
| # | ||
| # @return [Object] | ||
| # | ||
| def self.client service, location:, transport: :grpc | ||
| endpoint = location == "global" ? "aiplatform.googleapis.com" : "#{location}-aiplatform.googleapis.com" | ||
| Google::Cloud::AIPlatform.public_send service, version: :v1, transport: transport do |config| | ||
| config.endpoint = endpoint | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,9 @@ libraries: | |
| ruby-cloud-gem-namespace: Google::Cloud::AIPlatform | ||
| ruby-cloud-service-override: AiPlatform=AIPlatform | ||
| keep: | ||
| - acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this? |
||
| - acceptance/google/cloud/ai_platform/v1/smoke_test.rb | ||
| - acceptance/helper.rb | ||
| - test/README.md | ||
| ruby: | ||
| wrapper_of: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to another question in the review, is this necessary? If the project wasn't specified, would the client fill in from ADC?