feat: add bigquery.ai.generate_table function (#2453) · google/bigframes@b925aa2 · GitHub
Skip to content

Commit b925aa2

Browse files
authored
feat: add bigquery.ai.generate_table function (#2453)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent a6aafaa commit b925aa2

4 files changed

Lines changed: 163 additions & 0 deletions

File tree

bigframes/bigquery/_operations/ai.py

Lines changed: 95 additions & 0 deletions

bigframes/bigquery/ai.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
generate_double,
2525
generate_embedding,
2626
generate_int,
27+
generate_table,
2728
generate_text,
2829
if_,
2930
score,
@@ -37,6 +38,7 @@
3738
"generate_double",
3839
"generate_embedding",
3940
"generate_int",
41+
"generate_table",
4042
"generate_text",
4143
"if_",
4244
"score",

tests/system/large/bigquery/test_ai.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ def test_generate_text_with_options(text_model):
9494

9595
# It basically asserts that the results are still returned.
9696
assert len(result) == 2
97+
98+
99+
def test_generate_table(text_model):
100+
df = bpd.DataFrame(
101+
{"prompt": ["Generate a table of 2 programming languages and their creators."]}
102+
)
103+
104+
result = ai.generate_table(
105+
text_model,
106+
df,
107+
output_schema="language STRING, creator STRING",
108+
)
109+
110+
assert "language" in result.columns
111+
assert "creator" in result.columns
112+
# The model may not always return the exact number of rows requested.
113+
assert len(result) > 0

tests/unit/bigquery/test_ai.py

Lines changed: 49 additions & 0 deletions

0 commit comments

Comments
 (0)