|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# pylint: disable=protected-access,bad-continuation,missing-function-docstring |
| 16 | + |
| 17 | +from tests.unit.vertexai.genai.replays import pytest_helper |
| 18 | +from vertexai._genai import types |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +METADATA_SCHEMA_URI = ( |
| 23 | + "gs://google-cloud-aiplatform/schema/dataset/metadata/multimodal_1.0.0.yaml" |
| 24 | +) |
| 25 | +BIGQUERY_TABLE_NAME = "vertex-sdk-dev.multimodal_dataset.test-table" |
| 26 | +DATASET = "8810841321427173376" |
| 27 | + |
| 28 | + |
| 29 | +def test_assess_dataset(client): |
| 30 | + operation = client.datasets._assess_multimodal_dataset( |
| 31 | + name=DATASET, |
| 32 | + tuning_resource_usage_assessment_config=types.TuningResourceUsageAssessmentConfig( |
| 33 | + model_name="gemini-2.5-flash-001" |
| 34 | + ), |
| 35 | + gemini_request_read_config=types.GeminiRequestReadConfig( |
| 36 | + template_config=types.GeminiTemplateConfig( |
| 37 | + gemini_example=types.GeminiExample( |
| 38 | + contents=[ |
| 39 | + { |
| 40 | + "role": "user", |
| 41 | + "parts": [{"text": "What is the capital of {name}?"}], |
| 42 | + } |
| 43 | + ], |
| 44 | + ), |
| 45 | + ), |
| 46 | + ), |
| 47 | + ) |
| 48 | + assert isinstance(operation, types.MultimodalDatasetOperation) |
| 49 | + |
| 50 | + |
| 51 | +def test_assess_tuning_resources(client): |
| 52 | + response = client.datasets.assess_tuning_resources( |
| 53 | + dataset_name=DATASET, |
| 54 | + model_name="gemini-2.5-flash-001", |
| 55 | + template_config=types.GeminiTemplateConfig( |
| 56 | + gemini_example=types.GeminiExample( |
| 57 | + contents=[ |
| 58 | + { |
| 59 | + "role": "user", |
| 60 | + "parts": [{"text": "What is the capital of {name}?"}], |
| 61 | + } |
| 62 | + ], |
| 63 | + ), |
| 64 | + ), |
| 65 | + ) |
| 66 | + assert isinstance(response, types.TuningResourceUsageAssessmentResult) |
| 67 | + |
| 68 | + |
| 69 | +pytestmark = pytest_helper.setup( |
| 70 | + file=__file__, |
| 71 | + globals_for_file=globals(), |
| 72 | +) |
| 73 | + |
| 74 | +pytest_plugins = ("pytest_asyncio",) |
| 75 | + |
| 76 | + |
| 77 | +@pytest.mark.asyncio |
| 78 | +async def test_assess_dataset_async(client): |
| 79 | + operation = await client.aio.datasets._assess_multimodal_dataset( |
| 80 | + name=DATASET, |
| 81 | + tuning_resource_usage_assessment_config=types.TuningResourceUsageAssessmentConfig( |
| 82 | + model_name="gemini-2.5-flash-001" |
| 83 | + ), |
| 84 | + gemini_request_read_config=types.GeminiRequestReadConfig( |
| 85 | + template_config=types.GeminiTemplateConfig( |
| 86 | + gemini_example=types.GeminiExample( |
| 87 | + contents=[ |
| 88 | + { |
| 89 | + "role": "user", |
| 90 | + "parts": [{"text": "What is the capital of {name}?"}], |
| 91 | + } |
| 92 | + ], |
| 93 | + ), |
| 94 | + ), |
| 95 | + ), |
| 96 | + ) |
| 97 | + assert isinstance(operation, types.MultimodalDatasetOperation) |
| 98 | + |
| 99 | + |
| 100 | +@pytest.mark.asyncio |
| 101 | +async def test_assess_tuning_resources_async(client): |
| 102 | + response = await client.aio.datasets.assess_tuning_resources( |
| 103 | + dataset_name=DATASET, |
| 104 | + model_name="gemini-2.5-flash-001", |
| 105 | + template_config=types.GeminiTemplateConfig( |
| 106 | + gemini_example=types.GeminiExample( |
| 107 | + contents=[ |
| 108 | + { |
| 109 | + "role": "user", |
| 110 | + "parts": [{"text": "What is the capital of {name}?"}], |
| 111 | + } |
| 112 | + ], |
| 113 | + ), |
| 114 | + ), |
| 115 | + ) |
| 116 | + assert isinstance(response, types.TuningResourceUsageAssessmentResult) |
0 commit comments