|
264 | 264 | "id": "hQft3o3OiouS"
|
265 | 265 | },
|
266 | 266 | "source": [
|
267 |
| - "# API Samples" |
| 267 | + "# API Examples" |
268 | 268 | ]
|
269 | 269 | },
|
270 | 270 | {
|
|
403 | 403 | "name": "stderr",
|
404 | 404 | "output_type": "stream",
|
405 | 405 | "text": [
|
406 |
| - "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:109: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
| 406 | + "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:108: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
407 | 407 | "`db_dtypes` is a preview feature and subject to change.\n",
|
408 | 408 | " warnings.warn(msg, bfe.PreviewWarning)\n"
|
409 | 409 | ]
|
|
594 | 594 | "name": "stderr",
|
595 | 595 | "output_type": "stream",
|
596 | 596 | "text": [
|
597 |
| - "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:109: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
| 597 | + "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:108: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
598 | 598 | "`db_dtypes` is a preview feature and subject to change.\n",
|
599 | 599 | " warnings.warn(msg, bfe.PreviewWarning)\n"
|
600 | 600 | ]
|
|
676 | 676 | },
|
677 | 677 | {
|
678 | 678 | "cell_type": "code",
|
679 |
| - "execution_count": null, |
| 679 | + "execution_count": 14, |
680 | 680 | "metadata": {
|
681 | 681 | "colab": {
|
682 | 682 | "base_uri": "https://localhost:8080/",
|
|
685 | 685 | "id": "PpL24AQFiouS",
|
686 | 686 | "outputId": "e7aff038-bf4b-4833-def8-fe2648e8885b"
|
687 | 687 | },
|
| 688 | + "outputs": [], |
| 689 | + "source": [ |
| 690 | + "# df.ai.map(\"What is the food made from {ingredient_1} and {ingredient_2}? One word only.\", output_column=\"food\", model=gemini_model)" |
| 691 | + ] |
| 692 | + }, |
| 693 | + { |
| 694 | + "cell_type": "markdown", |
| 695 | + "metadata": {}, |
| 696 | + "source": [ |
| 697 | + "### AI Extraction\n", |
| 698 | + "\n", |
| 699 | + "AI mapping is also able to extract multiple pieces of information based on your prompt, because the output schema keys can carry semantic meanings:" |
| 700 | + ] |
| 701 | + }, |
| 702 | + { |
| 703 | + "cell_type": "code", |
| 704 | + "execution_count": 15, |
| 705 | + "metadata": {}, |
688 | 706 | "outputs": [
|
689 | 707 | {
|
690 | 708 | "name": "stderr",
|
691 | 709 | "output_type": "stream",
|
692 | 710 | "text": [
|
693 |
| - "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:114: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
| 711 | + "/usr/local/google/home/sycai/src/python-bigquery-dataframes/bigframes/core/array_value.py:108: PreviewWarning: JSON column interpretation as a custom PyArrow extention in\n", |
694 | 712 | "`db_dtypes` is a preview feature and subject to change.\n",
|
695 | 713 | " warnings.warn(msg, bfe.PreviewWarning)\n"
|
696 | 714 | ]
|
|
716 | 734 | " <thead>\n",
|
717 | 735 | " <tr style=\"text-align: right;\">\n",
|
718 | 736 | " <th></th>\n",
|
719 |
| - " <th>ingredient_1</th>\n", |
720 |
| - " <th>ingredient_2</th>\n", |
721 |
| - " <th>food</th>\n", |
| 737 | + " <th>text</th>\n", |
| 738 | + " <th>person</th>\n", |
| 739 | + " <th>address</th>\n", |
722 | 740 | " </tr>\n",
|
723 | 741 | " </thead>\n",
|
724 | 742 | " <tbody>\n",
|
725 | 743 | " <tr>\n",
|
726 | 744 | " <th>0</th>\n",
|
727 |
| - " <td>Bun</td>\n", |
728 |
| - " <td>Beef Patty</td>\n", |
729 |
| - " <td>Burger</td>\n", |
| 745 | + " <td>Elmo lives at 123 Sesame Street.</td>\n", |
| 746 | + " <td>Elmo</td>\n", |
| 747 | + " <td>123 Sesame Street</td>\n", |
730 | 748 | " </tr>\n",
|
731 | 749 | " <tr>\n",
|
732 | 750 | " <th>1</th>\n",
|
733 |
| - " <td>Soy Bean</td>\n", |
734 |
| - " <td>Bittern</td>\n", |
735 |
| - " <td>Tofu</td>\n", |
736 |
| - " </tr>\n", |
737 |
| - " <tr>\n", |
738 |
| - " <th>2</th>\n", |
739 |
| - " <td>Sausage</td>\n", |
740 |
| - " <td>Long Bread</td>\n", |
741 |
| - " <td>Hotdog</td>\n", |
| 751 | + " <td>124 Conch Street is SpongeBob's home</td>\n", |
| 752 | + " <td>SpongeBob</td>\n", |
| 753 | + " <td>124 Conch Street</td>\n", |
742 | 754 | " </tr>\n",
|
743 | 755 | " </tbody>\n",
|
744 | 756 | "</table>\n",
|
745 |
| - "<p>3 rows × 3 columns</p>\n", |
746 |
| - "</div>[3 rows x 3 columns in total]" |
| 757 | + "<p>2 rows × 3 columns</p>\n", |
| 758 | + "</div>[2 rows x 3 columns in total]" |
747 | 759 | ],
|
748 | 760 | "text/plain": [
|
749 |
| - " ingredient_1 ingredient_2 food\n", |
750 |
| - "0 Bun Beef Patty Burger\n", |
751 |
| - "\n", |
752 |
| - "1 Soy Bean Bittern Tofu\n", |
753 |
| - "\n", |
754 |
| - "2 Sausage Long Bread Hotdog\n", |
755 |
| - "\n", |
| 761 | + " text person address\n", |
| 762 | + "0 Elmo lives at 123 Sesame Street. Elmo 123 Sesame Street\n", |
| 763 | + "1 124 Conch Street is SpongeBob's home SpongeBob 124 Conch Street\n", |
756 | 764 | "\n",
|
757 |
| - "[3 rows x 3 columns]" |
| 765 | + "[2 rows x 3 columns]" |
758 | 766 | ]
|
759 | 767 | },
|
760 |
| - "execution_count": 13, |
| 768 | + "execution_count": 15, |
761 | 769 | "metadata": {},
|
762 | 770 | "output_type": "execute_result"
|
763 | 771 | }
|
764 | 772 | ],
|
765 | 773 | "source": [
|
766 |
| - "# df.ai.map(\"What is the food made from {ingredient_1} and {ingredient_2}? One word only.\", output_column=\"food\", model=gemini_model)" |
| 774 | + "df = bpd.DataFrame({\n", |
| 775 | + " \"text\": [\n", |
| 776 | + " \"Elmo lives at 123 Sesame Street.\", \n", |
| 777 | + " \"124 Conch Street is SpongeBob's home\",\n", |
| 778 | + " ]\n", |
| 779 | + "})\n", |
| 780 | + "df.ai.map(\"{text}\", model=gemini_model, output_schema={\"person\": \"string\", \"address\": \"string\"})" |
767 | 781 | ]
|
768 | 782 | },
|
769 | 783 | {
|
|
0 commit comments