Content-Length: 523975 | pFad | https://github.com/googleapis/python-aiplatform/commit/#start-of-content

682FF5DB chore: add batch_eval method to Vertex Evals · googleapis/python-aiplatform@b15743d · GitHub
Skip to content

Commit b15743d

Browse files
sararobcopybara-github
authored andcommitted
chore: add batch_eval method to Vertex Evals
PiperOrigin-RevId: 762169440
1 parent 959e0ec commit b15743d

File tree

4 files changed

+1356
-24
lines changed

4 files changed

+1356
-24
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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
16+
17+
import importlib
18+
from unittest import mock
19+
20+
from google.cloud import aiplatform
21+
import vertexai
22+
from google.cloud.aiplatform import initializer as aiplatform_initializer
23+
from vertexai import _genai
24+
25+
import pytest
26+
27+
_TEST_PROJECT = "test-project"
28+
_TEST_LOCATION = "us-central1"
29+
30+
31+
pytestmark = pytest.mark.usefixtures("google_auth_mock")
32+
33+
34+
class TestEvals:
35+
"""Unit tests for the GenAI client."""
36+
37+
def setup_method(self):
38+
importlib.reload(aiplatform_initializer)
39+
importlib.reload(aiplatform)
40+
importlib.reload(vertexai)
41+
vertexai.init(
42+
project=_TEST_PROJECT,
43+
location=_TEST_LOCATION,
44+
)
45+
46+
@pytest.mark.usefixtures("google_auth_mock")
47+
def test_evaluate_instances(self):
48+
test_client = _genai.client.Client(
49+
project=_TEST_PROJECT, location=_TEST_LOCATION
50+
)
51+
with mock.patch.object(
52+
test_client.evals, "_evaluate_instances"
53+
) as mock_evaluate:
54+
test_client.evals._evaluate_instances(bleu_input=_genai.types.BleuInput())
55+
mock_evaluate.assert_called_once_with(bleu_input=_genai.types.BleuInput())
56+
57+
@pytest.mark.usefixtures("google_auth_mock")
58+
def test_eval_run(self):
59+
test_client = _genai.client.Client(
60+
project=_TEST_PROJECT, location=_TEST_LOCATION
61+
)
62+
with pytest.raises(NotImplementedError):
63+
test_client.evals.run()
64+
65+
@pytest.mark.usefixtures("google_auth_mock")
66+
def test_eval_batch_eval(self):
67+
test_client = _genai.client.Client(
68+
project=_TEST_PROJECT, location=_TEST_LOCATION
69+
)
70+
with mock.patch.object(test_client.evals, "batch_eval") as mock_batch_eval:
71+
test_client.evals.batch_eval(
72+
dataset=_genai.types.EvaluationDataset(),
73+
metrics=[_genai.types.Metric()],
74+
output_config=_genai.types.OutputConfig(),
75+
autorater_config=_genai.types.AutoraterConfig(),
76+
config=_genai.types.EvaluateDatasetConfig(),
77+
)
78+
mock_batch_eval.assert_called_once()

tests/unit/vertexai/genai/test_genai_client.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Copyright 2025 Google LLC
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,14 +14,14 @@
1614
#
1715

1816
# pylint: disable=protected-access,bad-continuation
19-
import pytest
17+
2018
import importlib
21-
from unittest import mock
19+
2220
from google.cloud import aiplatform
2321
import vertexai
2422
from google.cloud.aiplatform import initializer as aiplatform_initializer
25-
2623
from vertexai import _genai
24+
import pytest
2725

2826
_TEST_PROJECT = "test-project"
2927
_TEST_LOCATION = "us-central1"
@@ -53,22 +51,3 @@ def test_genai_client(self):
5351
assert test_client._api_client.vertexai
5452
assert test_client._api_client.project == _TEST_PROJECT
5553
assert test_client._api_client.location == _TEST_LOCATION
56-
57-
@pytest.mark.usefixtures("google_auth_mock")
58-
def test_evaluate_instances(self):
59-
test_client = _genai.client.Client(
60-
project=_TEST_PROJECT, location=_TEST_LOCATION
61-
)
62-
with mock.patch.object(
63-
test_client.evals, "_evaluate_instances"
64-
) as mock_evaluate:
65-
test_client.evals._evaluate_instances(bleu_input=_genai.types.BleuInput())
66-
mock_evaluate.assert_called_once_with(bleu_input=_genai.types.BleuInput())
67-
68-
@pytest.mark.usefixtures("google_auth_mock")
69-
def test_eval_run(self):
70-
test_client = _genai.client.Client(
71-
project=_TEST_PROJECT, location=_TEST_LOCATION
72-
)
73-
with pytest.raises(NotImplementedError):
74-
test_client.evals.run()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-aiplatform/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy