|
| 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 | +import json |
| 16 | +import sys |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | +from bigframes import dataframe |
| 21 | +from bigframes import operations as ops |
| 22 | +from bigframes.testing import utils |
| 23 | + |
| 24 | +pytest.importorskip("pytest_snapshot") |
| 25 | + |
| 26 | + |
| 27 | +def test_ai_generate_bool(scalar_types_df: dataframe.DataFrame, snapshot): |
| 28 | + col_name = "string_col" |
| 29 | + |
| 30 | + op = ops.AIGenerateBool( |
| 31 | + prompt_context=(None, " is the same as ", None), |
| 32 | + connection_id="test_connection_id", |
| 33 | + endpoint="gemini-2.5-flash", |
| 34 | + request_type="shared", |
| 35 | + model_params=None, |
| 36 | + ) |
| 37 | + |
| 38 | + sql = utils._apply_unary_ops( |
| 39 | + scalar_types_df, [op.as_expr(col_name, col_name)], ["result"] |
| 40 | + ) |
| 41 | + |
| 42 | + snapshot.assert_match(sql, "out.sql") |
| 43 | + |
| 44 | + |
| 45 | +def test_ai_generate_bool_with_model_param( |
| 46 | + scalar_types_df: dataframe.DataFrame, snapshot |
| 47 | +): |
| 48 | + if sys.version_info < (3, 10): |
| 49 | + pytest.skip( |
| 50 | + "Skip test because SQLGLot cannot compile model params to JSON at this env." |
| 51 | + ) |
| 52 | + |
| 53 | + col_name = "string_col" |
| 54 | + |
| 55 | + op = ops.AIGenerateBool( |
| 56 | + prompt_context=(None, " is the same as ", None), |
| 57 | + connection_id="test_connection_id", |
| 58 | + endpoint=None, |
| 59 | + request_type="shared", |
| 60 | + model_params=json.dumps(dict()), |
| 61 | + ) |
| 62 | + |
| 63 | + sql = utils._apply_unary_ops( |
| 64 | + scalar_types_df, [op.as_expr(col_name, col_name)], ["result"] |
| 65 | + ) |
| 66 | + |
| 67 | + snapshot.assert_match(sql, "out.sql") |
0 commit comments