{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "acd53f9d", "metadata": {}, "outputs": [], "source": [ "# Copyright 2025 Google LLC\n", "#\n", "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "id": "e75ce682", "metadata": {}, "source": [ "# BigQuery DataFrames (BigFrames) AI Functions\n", "\n", "
\n",
" \n",
" Run in Colab\n",
" \n",
" | \n",
" \n",
" \n",
" \n",
" View on GitHub\n",
" \n",
" | \n",
" \n",
" \n",
" | \n",
"
0 {\"result\":\"Salad\",\"full_response\":{\"candidates...\n",
"1 {\"result\":\"Hotdog\",\"full_response\":{\"candidate..."
],
"text/plain": [
"0 {\"result\":\"Salad\",\"full_response\":{\"candidates...\n",
"1 {\"result\":\"Hotdog\",\"full_response\":{\"candidate...\n",
"Name: 0, dtype: string"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import bigframes.bigquery as bbq\n",
"\n",
"ingredients1 = bpd.Series([\"Lettuce\", \"Sausage\"])\n",
"ingredients2 = bpd.Series([\"Cucumber\", \"Long Bread\"])\n",
"\n",
"prompt = (\"What's the food made from \", ingredients1, \" and \", ingredients2, \" One word only\")\n",
"bbq.ai.generate(prompt)"
]
},
{
"cell_type": "markdown",
"id": "03953835",
"metadata": {},
"source": [
"The function returns a series of structs. The `'result'` field holds the answer, while more metadata can be found in the `'full_response'` field. The `'status'` field tells you whether LLM made a successful response for that specific row. "
]
},
{
"cell_type": "markdown",
"id": "b606c51f",
"metadata": {},
"source": [
"You can also include additional model parameters into your function call, as long as they conform to the structure of `generateContent` [request body format](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/generateContent#request-body). In the next example, you use `maxOutputTokens` to limit the length of the generated content."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a3229a8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"0" ], "text/plain": [ "0\n", "1
| \n", " | creature | \n", "category | \n", "
|---|---|---|
| 0 | \n", "Cat | \n", "mammal | \n", "
| 1 | \n", "Salmon | \n", "fish | \n", "
2 rows × 2 columns
\n", "| \n", " | animals | \n", "relative_weight | \n", "
|---|---|---|
| 1 | \n", "spider | \n", "1.0 | \n", "
| 0 | \n", "tiger | \n", "7.0 | \n", "
| 2 | \n", "blue whale | \n", "10.0 | \n", "
3 rows × 2 columns
\n", "| \n", " | animal | \n", "category | \n", "
|---|---|---|
| 0 | \n", "tiger | \n", "mammal | \n", "
| 1 | \n", "spider | \n", "anthropod | \n", "
| 2 | \n", "blue whale | \n", "mammal | \n", "
| 3 | \n", "salmon | \n", "fish | \n", "
4 rows × 2 columns
\n", "| \n", " | animal | \n", "category | \n", "
|---|---|---|
| 0 | \n", "tiger | \n", "mammal | \n", "
| 1 | \n", "spider | \n", "mammal | \n", "
2 rows × 2 columns
\n", "