|
| 1 | +# Copyright 2026 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 | +from unittest import mock |
| 16 | + |
| 17 | +import pytest |
| 18 | +from google.cloud import bigquery |
| 19 | + |
| 20 | +import bigframes.session |
| 21 | +from bigframes.ml import llm |
| 22 | + |
| 23 | + |
| 24 | +def test_gemini_text_generator_default_model(): |
| 25 | + mock_session = mock.create_autospec(spec=bigframes.session.Session) |
| 26 | + mock_session._create_bq_connection.return_value = ( |
| 27 | + "projects/test-project/locations/us-central1/connections/test-conn" |
| 28 | + ) |
| 29 | + mock_session._anonymous_dataset = bigquery.DatasetReference( |
| 30 | + "test-project", "test_dataset" |
| 31 | + ) |
| 32 | + mock_job = mock.MagicMock() |
| 33 | + mock_job.destination.project = "test-project" |
| 34 | + mock_job.destination.dataset_id = "test_dataset" |
| 35 | + mock_job.destination.table_id = "test_model" |
| 36 | + mock_session._start_query_ml_ddl.return_value = (None, mock_job) |
| 37 | + mock_session.bqclient.get_model.return_value = mock.MagicMock(spec=bigquery.Model) |
| 38 | + |
| 39 | + with pytest.warns( |
| 40 | + FutureWarning, match="default model will be removed in BigFrames 3.0" |
| 41 | + ): |
| 42 | + model = llm.GeminiTextGenerator( |
| 43 | + session=mock_session, |
| 44 | + connection_name="test-conn", |
| 45 | + ) |
| 46 | + |
| 47 | + assert model.model_name == "gemini-2.5-flash" |
| 48 | + mock_session._start_query_ml_ddl.assert_called_once() |
| 49 | + generated_sql = mock_session._start_query_ml_ddl.call_args[0][0] |
| 50 | + assert "gemini-2.5-flash" in generated_sql |
0 commit comments