GeezerVison is showing github.com — feat: use end user credentials for `bigframes.bigquery.ai` functions … · google/bigframes@7c062a6
File treeExpand file treeCollapse file tree Open diff view settings core/compile/sqlglot/expressions
tests/unit/core/compile/sqlglot/expressions test_ai_generate_bool_with_connection_id test_ai_generate_bool_with_model_param test_ai_generate_double_with_connection_id test_ai_generate_double_with_model_param test_ai_generate_int_with_connection_id test_ai_generate_int_with_model_param test_ai_generate_with_connection_id test_ai_generate_with_model_param test_ai_generate_with_output_schema
third_party/bigframes_vendored/ibis/expr/operations
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bigframes/bigquery/_operations/ai.py +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,7 +88,7 @@ def generate( | 88 | 88 | or pandas Series. | 89 | 89 | connection_id (str, optional): | 90 | 90 | Specifies the connection to use to communicate with the model. For example, `myproject.us.myconnection`. | 91 | | - If not provided, the connection from the current session will be used. | | 91 | + If not provided, the query uses your end-user credential. | 92 | 92 | endpoint (str, optional): | 93 | 93 | Specifies the Vertex AI endpoint to use for the model. For example `"gemini-2.5-flash"`. You can specify any | 94 | 94 | generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically identifies and | @@ -131,7 +131,7 @@ def generate( | 131 | 131 |
| 132 | 132 | operator = ai_ops.AIGenerate( | 133 | 133 | prompt_context=tuple(prompt_context), | 134 | | - connection_id=_resolve_connection_id(series_list[0], connection_id), | | 134 | + connection_id=connection_id, | 135 | 135 | endpoint=endpoint, | 136 | 136 | request_type=request_type, | 137 | 137 | model_params=json.dumps(model_params) if model_params else None, | @@ -186,7 +186,7 @@ def generate_bool( | 186 | 186 | or pandas Series. | 187 | 187 | connection_id (str, optional): | 188 | 188 | Specifies the connection to use to communicate with the model. For example, `myproject.us.myconnection`. | 189 | | - If not provided, the connection from the current session will be used. | | 189 | + If not provided, the query uses your end-user credential. | 190 | 190 | endpoint (str, optional): | 191 | 191 | Specifies the Vertex AI endpoint to use for the model. For example `"gemini-2.5-flash"`. You can specify any | 192 | 192 | generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically identifies and | @@ -216,7 +216,7 @@ def generate_bool( | 216 | 216 |
| 217 | 217 | operator = ai_ops.AIGenerateBool( | 218 | 218 | prompt_context=tuple(prompt_context), | 219 | | - connection_id=_resolve_connection_id(series_list[0], connection_id), | | 219 | + connection_id=connection_id, | 220 | 220 | endpoint=endpoint, | 221 | 221 | request_type=request_type, | 222 | 222 | model_params=json.dumps(model_params) if model_params else None, | @@ -267,7 +267,7 @@ def generate_int( | 267 | 267 | or pandas Series. | 268 | 268 | connection_id (str, optional): | 269 | 269 | Specifies the connection to use to communicate with the model. For example, `myproject.us.myconnection`. | 270 | | - If not provided, the connection from the current session will be used. | | 270 | + If not provided, the query uses your end-user credential. | 271 | 271 | endpoint (str, optional): | 272 | 272 | Specifies the Vertex AI endpoint to use for the model. For example `"gemini-2.5-flash"`. You can specify any | 273 | 273 | generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically identifies and | @@ -297,7 +297,7 @@ def generate_int( | 297 | 297 |
| 298 | 298 | operator = ai_ops.AIGenerateInt( | 299 | 299 | prompt_context=tuple(prompt_context), | 300 | | - connection_id=_resolve_connection_id(series_list[0], connection_id), | | 300 | + connection_id=connection_id, | 301 | 301 | endpoint=endpoint, | 302 | 302 | request_type=request_type, | 303 | 303 | model_params=json.dumps(model_params) if model_params else None, | @@ -348,7 +348,7 @@ def generate_double( | 348 | 348 | or pandas Series. | 349 | 349 | connection_id (str, optional): | 350 | 350 | Specifies the connection to use to communicate with the model. For example, `myproject.us.myconnection`. | 351 | | - If not provided, the connection from the current session will be used. | | 351 | + If not provided, the query uses your end-user credential. | 352 | 352 | endpoint (str, optional): | 353 | 353 | Specifies the Vertex AI endpoint to use for the model. For example `"gemini-2.5-flash"`. You can specify any | 354 | 354 | generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically identifies and | @@ -378,7 +378,7 @@ def generate_double( | 378 | 378 |
| 379 | 379 | operator = ai_ops.AIGenerateDouble( | 380 | 380 | prompt_context=tuple(prompt_context), | 381 | | - connection_id=_resolve_connection_id(series_list[0], connection_id), | | 381 | + connection_id=connection_id, | 382 | 382 | endpoint=endpoint, | 383 | 383 | request_type=request_type, | 384 | 384 | model_params=json.dumps(model_params) if model_params else None, | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/core/compile/sqlglot/expressions/ai_ops.py +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,10 +104,13 @@ def _construct_named_args(op: ops.NaryOp) -> list[sge.Kwarg]: | 104 | 104 |
| 105 | 105 | op_args = asdict(op) | 106 | 106 |
| 107 | | - connection_id = op_args["connection_id"] | 108 | | - args.append( | 109 | | - sge.Kwarg(this="connection_id", expression=sge.Literal.string(connection_id)) | 110 | | - ) | | 107 | + connection_id = op_args.get("connection_id", None) | | 108 | + if connection_id is not None: | | 109 | + args.append( | | 110 | + sge.Kwarg( | | 111 | + this="connection_id", expression=sge.Literal.string(connection_id) | | 112 | + ) | | 113 | + ) | 111 | 114 |
| 112 | 115 | endpoit = op_args.get("endpoint", None) | 113 | 116 | if endpoit is not None: | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/operations/ai_ops.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,7 +29,7 @@ class AIGenerate(base_ops.NaryOp): | 29 | 29 | name: ClassVar[str] = "ai_generate" | 30 | 30 |
| 31 | 31 | prompt_context: Tuple[str | None, ...] | 32 | | - connection_id: str | | 32 | + connection_id: str | None | 33 | 33 | endpoint: str | None | 34 | 34 | request_type: Literal["dedicated", "shared", "unspecified"] | 35 | 35 | model_params: str | None | @@ -57,7 +57,7 @@ class AIGenerateBool(base_ops.NaryOp): | 57 | 57 | name: ClassVar[str] = "ai_generate_bool" | 58 | 58 |
| 59 | 59 | prompt_context: Tuple[str | None, ...] | 60 | | - connection_id: str | | 60 | + connection_id: str | None | 61 | 61 | endpoint: str | None | 62 | 62 | request_type: Literal["dedicated", "shared", "unspecified"] | 63 | 63 | model_params: str | None | @@ -79,7 +79,7 @@ class AIGenerateInt(base_ops.NaryOp): | 79 | 79 | name: ClassVar[str] = "ai_generate_int" | 80 | 80 |
| 81 | 81 | prompt_context: Tuple[str | None, ...] | 82 | | - connection_id: str | | 82 | + connection_id: str | None | 83 | 83 | endpoint: str | None | 84 | 84 | request_type: Literal["dedicated", "shared", "unspecified"] | 85 | 85 | model_params: str | None | @@ -101,7 +101,7 @@ class AIGenerateDouble(base_ops.NaryOp): | 101 | 101 | name: ClassVar[str] = "ai_generate_double" | 102 | 102 |
| 103 | 103 | prompt_context: Tuple[str | None, ...] | 104 | | - connection_id: str | | 104 | + connection_id: str | None | 105 | 105 | endpoint: str | None | 106 | 106 | request_type: Literal["dedicated", "shared", "unspecified"] | 107 | 107 | model_params: str | None | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate/out.sql -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ WITH `bfcte_0` AS ( | 7 | 7 | *, | 8 | 8 | AI.GENERATE( | 9 | 9 | prompt => (`string_col`, ' is the same as ', `string_col`), | 10 | | - connection_id => 'bigframes-dev.us.bigframes-default-connection', | 11 | 10 | endpoint => 'gemini-2.5-flash', | 12 | 11 | request_type => 'SHARED' | 13 | 12 | ) AS `bfcol_1` | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool/out.sql -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ WITH `bfcte_0` AS ( | 7 | 7 | *, | 8 | 8 | AI.GENERATE_BOOL( | 9 | 9 | prompt => (`string_col`, ' is the same as ', `string_col`), | 10 | | - connection_id => 'bigframes-dev.us.bigframes-default-connection', | 11 | 10 | endpoint => 'gemini-2.5-flash', | 12 | 11 | request_type => 'SHARED' | 13 | 12 | ) AS `bfcol_1` | |
Collapse file Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +WITH `bfcte_0` AS ( | | 2 | + SELECT | | 3 | + `string_col` | | 4 | + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` | | 5 | +), `bfcte_1` AS ( | | 6 | + SELECT | | 7 | + *, | | 8 | + AI.GENERATE_BOOL( | | 9 | + prompt => (`string_col`, ' is the same as ', `string_col`), | | 10 | + connection_id => 'bigframes-dev.us.bigframes-default-connection', | | 11 | + endpoint => 'gemini-2.5-flash', | | 12 | + request_type => 'SHARED' | | 13 | + ) AS `bfcol_1` | | 14 | + FROM `bfcte_0` | | 15 | +) | | 16 | +SELECT | | 17 | + `bfcol_1` AS `result` | | 18 | +FROM `bfcte_1` |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_model_param/out.sql -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ WITH `bfcte_0` AS ( | 7 | 7 | *, | 8 | 8 | AI.GENERATE_BOOL( | 9 | 9 | prompt => (`string_col`, ' is the same as ', `string_col`), | 10 | | - connection_id => 'bigframes-dev.us.bigframes-default-connection', | 11 | 10 | request_type => 'SHARED', | 12 | 11 | model_params => JSON '{}' | 13 | 12 | ) AS `bfcol_1` | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double/out.sql -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ WITH `bfcte_0` AS ( | 7 | 7 | *, | 8 | 8 | AI.GENERATE_DOUBLE( | 9 | 9 | prompt => (`string_col`, ' is the same as ', `string_col`), | 10 | | - connection_id => 'bigframes-dev.us.bigframes-default-connection', | 11 | 10 | endpoint => 'gemini-2.5-flash', | 12 | 11 | request_type => 'SHARED' | 13 | 12 | ) AS `bfcol_1` | |
Collapse file Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +WITH `bfcte_0` AS ( | | 2 | + SELECT | | 3 | + `string_col` | | 4 | + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` | | 5 | +), `bfcte_1` AS ( | | 6 | + SELECT | | 7 | + *, | | 8 | + AI.GENERATE_DOUBLE( | | 9 | + prompt => (`string_col`, ' is the same as ', `string_col`), | | 10 | + connection_id => 'bigframes-dev.us.bigframes-default-connection', | | 11 | + endpoint => 'gemini-2.5-flash', | | 12 | + request_type => 'SHARED' | | 13 | + ) AS `bfcol_1` | | 14 | + FROM `bfcte_0` | | 15 | +) | | 16 | +SELECT | | 17 | + `bfcol_1` AS `result` | | 18 | +FROM `bfcte_1` |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_model_param/out.sql -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ WITH `bfcte_0` AS ( | 7 | 7 | *, | 8 | 8 | AI.GENERATE_DOUBLE( | 9 | 9 | prompt => (`string_col`, ' is the same as ', `string_col`), | 10 | | - connection_id => 'bigframes-dev.us.bigframes-default-connection', | 11 | 10 | request_type => 'SHARED', | 12 | 11 | model_params => JSON '{}' | 13 | 12 | ) AS `bfcol_1` | |
|