From 89890a5b10c9e8a8c9d93d834b6295a6edec8dd4 Mon Sep 17 00:00:00 2001 From: David del Real Sifuentes Date: Wed, 12 Aug 2026 19:38:04 +0000 Subject: [PATCH] chore(generative_ai): remove deprecated samples migrated to genai These samples are no longer in use in devsite. They have been migrated to genai with new region tags and updated code. --- .../pairwise_summarization_quality.py | 106 ------------------ generative_ai/evaluation/test_evaluation.py | 6 - generative_ai/labels/labels_example.py | 53 --------- generative_ai/labels/noxfile_config.py | 42 ------- generative_ai/labels/requirements-test.txt | 2 - generative_ai/labels/requirements.txt | 1 - generative_ai/labels/test_labels_examples.py | 20 ---- .../provisioned_throughput/noxfile_config.py | 42 ------- .../provisioned_throughput_with_txt.py | 55 --------- .../requirements-test.txt | 4 - .../provisioned_throughput/requirements.txt | 2 - .../test_provisioned_throughput_examples.py | 21 ---- .../text_generation/text_example01.py | 47 -------- 13 files changed, 401 deletions(-) delete mode 100644 generative_ai/evaluation/pairwise_summarization_quality.py delete mode 100644 generative_ai/labels/labels_example.py delete mode 100644 generative_ai/labels/noxfile_config.py delete mode 100644 generative_ai/labels/requirements-test.txt delete mode 100644 generative_ai/labels/requirements.txt delete mode 100644 generative_ai/labels/test_labels_examples.py delete mode 100644 generative_ai/provisioned_throughput/noxfile_config.py delete mode 100644 generative_ai/provisioned_throughput/provisioned_throughput_with_txt.py delete mode 100644 generative_ai/provisioned_throughput/requirements-test.txt delete mode 100644 generative_ai/provisioned_throughput/requirements.txt delete mode 100644 generative_ai/provisioned_throughput/test_provisioned_throughput_examples.py delete mode 100644 generative_ai/text_generation/text_example01.py diff --git a/generative_ai/evaluation/pairwise_summarization_quality.py b/generative_ai/evaluation/pairwise_summarization_quality.py deleted file mode 100644 index 88c89871904..00000000000 --- a/generative_ai/evaluation/pairwise_summarization_quality.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2024 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. -import os - -from vertexai.preview.evaluation import EvalResult - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def evaluate_output() -> EvalResult: - # [START generativeaionvertexai_evaluation_pairwise_summarization_quality] - import pandas as pd - - import vertexai - from vertexai.generative_models import GenerativeModel - from vertexai.evaluation import ( - EvalTask, - PairwiseMetric, - MetricPromptTemplateExamples, - ) - - # TODO(developer): Update & uncomment line below - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - prompt = """ - Summarize the text such that a five-year-old can understand. - - # Text - - As part of a comprehensive initiative to tackle urban congestion and foster - sustainable urban living, a major city has revealed ambitious plans for an - extensive overhaul of its public transportation system. The project aims not - only to improve the efficiency and reliability of public transit but also to - reduce the city\'s carbon footprint and promote eco-friendly commuting options. - City officials anticipate that this strategic investment will enhance - accessibility for residents and visitors alike, ushering in a new era of - efficient, environmentally conscious urban transportation. - """ - - eval_dataset = pd.DataFrame({"prompt": [prompt]}) - - # Baseline model for pairwise comparison - baseline_model = GenerativeModel("gemini-2.0-flash-lite-001") - - # Candidate model for pairwise comparison - candidate_model = GenerativeModel( - "gemini-2.0-flash-001", generation_config={"temperature": 0.4} - ) - - prompt_template = MetricPromptTemplateExamples.get_prompt_template( - "pairwise_summarization_quality" - ) - - summarization_quality_metric = PairwiseMetric( - metric="pairwise_summarization_quality", - metric_prompt_template=prompt_template, - baseline_model=baseline_model, - ) - - eval_task = EvalTask( - dataset=eval_dataset, - metrics=[summarization_quality_metric], - experiment="pairwise-experiment", - ) - result = eval_task.evaluate(model=candidate_model) - - baseline_model_response = result.metrics_table["baseline_model_response"].iloc[0] - candidate_model_response = result.metrics_table["response"].iloc[0] - winner_model = result.metrics_table[ - "pairwise_summarization_quality/pairwise_choice" - ].iloc[0] - explanation = result.metrics_table[ - "pairwise_summarization_quality/explanation" - ].iloc[0] - - print(f"Baseline's story:\n{baseline_model_response}") - print(f"Candidate's story:\n{candidate_model_response}") - print(f"Winner: {winner_model}") - print(f"Explanation: {explanation}") - # Example response: - # Baseline's story: - # A big city wants to make it easier for people to get around without using cars! They're going to make buses and trains ... - # - # Candidate's story: - # A big city wants to make it easier for people to get around without using cars! ... This will help keep the air clean ... - # - # Winner: CANDIDATE - # Explanation: Both responses adhere to the prompt's constraints, are grounded in the provided text, and ... However, Response B ... - # [END generativeaionvertexai_evaluation_pairwise_summarization_quality] - return result - - -if __name__ == "__main__": - evaluate_output() diff --git a/generative_ai/evaluation/test_evaluation.py b/generative_ai/evaluation/test_evaluation.py index 8263eb97709..0473c4b304b 100644 --- a/generative_ai/evaluation/test_evaluation.py +++ b/generative_ai/evaluation/test_evaluation.py @@ -13,14 +13,8 @@ # limitations under the License. import get_rouge_score -import pairwise_summarization_quality def test_create_evaluation_task() -> None: response = get_rouge_score.get_rouge_score() assert response - - -def test_pairwise_evaluation_summarization_quality() -> None: - response = pairwise_summarization_quality.evaluate_output() - assert response diff --git a/generative_ai/labels/labels_example.py b/generative_ai/labels/labels_example.py deleted file mode 100644 index 23168e7d461..00000000000 --- a/generative_ai/labels/labels_example.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2024 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. -import os - -from vertexai.generative_models import GenerationResponse - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def generate_content() -> GenerationResponse: - # [START generativeaionvertexai_gemini_set_labels] - import vertexai - - from vertexai.generative_models import GenerativeModel - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = GenerativeModel("gemini-2.0-flash-001") - - prompt = "What is Generative AI?" - response = model.generate_content( - prompt, - # Example Labels - labels={ - "team": "research", - "component": "frontend", - "environment": "production", - }, - ) - - print(response.text) - # Example response: - # Generative AI is a type of Artificial Intelligence focused on **creating new content** based on existing data. - - # [END generativeaionvertexai_gemini_set_labels] - return response - - -if __name__ == "__main__": - generate_content() diff --git a/generative_ai/labels/noxfile_config.py b/generative_ai/labels/noxfile_config.py deleted file mode 100644 index 0973c8621c7..00000000000 --- a/generative_ai/labels/noxfile_config.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2021 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 -# -# http://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. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be imported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - "ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": True, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/generative_ai/labels/requirements-test.txt b/generative_ai/labels/requirements-test.txt deleted file mode 100644 index cefab43dffa..00000000000 --- a/generative_ai/labels/requirements-test.txt +++ /dev/null @@ -1,2 +0,0 @@ -google-api-core==2.23.0 -pytest==9.0.3; python_version >= "3.10" diff --git a/generative_ai/labels/requirements.txt b/generative_ai/labels/requirements.txt deleted file mode 100644 index 567a82bafee..00000000000 --- a/generative_ai/labels/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -google-cloud-aiplatform==1.157.0 diff --git a/generative_ai/labels/test_labels_examples.py b/generative_ai/labels/test_labels_examples.py deleted file mode 100644 index 52a21689861..00000000000 --- a/generative_ai/labels/test_labels_examples.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2024 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. - -import labels_example - - -def test_set_labels() -> None: - response = labels_example.generate_content() - assert response diff --git a/generative_ai/provisioned_throughput/noxfile_config.py b/generative_ai/provisioned_throughput/noxfile_config.py deleted file mode 100644 index 0973c8621c7..00000000000 --- a/generative_ai/provisioned_throughput/noxfile_config.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2021 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 -# -# http://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. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be imported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - "ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": True, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/generative_ai/provisioned_throughput/provisioned_throughput_with_txt.py b/generative_ai/provisioned_throughput/provisioned_throughput_with_txt.py deleted file mode 100644 index 8da294ab6aa..00000000000 --- a/generative_ai/provisioned_throughput/provisioned_throughput_with_txt.py +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2025 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. -import os - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def generate_content() -> str: - # [START generativeaionvertexai_provisioned_throughput_with_txt] - import vertexai - from vertexai.generative_models import GenerativeModel - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init( - project=PROJECT_ID, - location="us-central1", - # Options: - # - "dedicated": Use Provisioned Throughput - # - "shared": Use pay-as-you-go - # https://cloud.google.com/vertex-ai/generative-ai/docs/use-provisioned-throughput - request_metadata=[("x-vertex-ai-llm-request-type", "shared")], - ) - - model = GenerativeModel("gemini-2.0-flash-001") - - response = model.generate_content( - "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?" - ) - - print(response.text) - # Example response: - # **Emphasizing the Dried Aspect:** - # * Everlasting Blooms - # * Dried & Delightful - # * The Petal Preserve - # ... - - # [END generativeaionvertexai_provisioned_throughput_with_txt] - return response.text - - -if __name__ == "__main__": - generate_content() diff --git a/generative_ai/provisioned_throughput/requirements-test.txt b/generative_ai/provisioned_throughput/requirements-test.txt deleted file mode 100644 index baa23bf9c3e..00000000000 --- a/generative_ai/provisioned_throughput/requirements-test.txt +++ /dev/null @@ -1,4 +0,0 @@ -backoff==2.2.1 -google-api-core==2.19.0 -pytest==9.0.3; python_version >= "3.10" -pytest-asyncio==0.23.6 diff --git a/generative_ai/provisioned_throughput/requirements.txt b/generative_ai/provisioned_throughput/requirements.txt deleted file mode 100644 index a1bd1c36ebd..00000000000 --- a/generative_ai/provisioned_throughput/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -google-cloud-aiplatform==1.157.0 -google-auth==2.38.0 diff --git a/generative_ai/provisioned_throughput/test_provisioned_throughput_examples.py b/generative_ai/provisioned_throughput/test_provisioned_throughput_examples.py deleted file mode 100644 index 89f7c38df62..00000000000 --- a/generative_ai/provisioned_throughput/test_provisioned_throughput_examples.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2025 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. - - -import provisioned_throughput_with_txt - - -def test_provisioned_throughput_with_txt() -> None: - response = provisioned_throughput_with_txt.generate_content() - assert response diff --git a/generative_ai/text_generation/text_example01.py b/generative_ai/text_generation/text_example01.py deleted file mode 100644 index 744ec4ee1ed..00000000000 --- a/generative_ai/text_generation/text_example01.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2024 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. -import os - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def generate_from_text_input() -> str: - # [START generativeaionvertexai_gemini_generate_from_text_input] - import vertexai - from vertexai.generative_models import GenerativeModel - - # TODO(developer): Update and un-comment below line - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = GenerativeModel("gemini-2.0-flash-001") - - response = model.generate_content( - "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?" - ) - - print(response.text) - # Example response: - # **Emphasizing the Dried Aspect:** - # * Everlasting Blooms - # * Dried & Delightful - # * The Petal Preserve - # ... - - # [END generativeaionvertexai_gemini_generate_from_text_input] - return response.text - - -if __name__ == "__main__": - generate_from_text_input()