From 685c13e157cfc8f10cc78de6af9174378dc761f2 Mon Sep 17 00:00:00 2001 From: Chad Juliano Date: Thu, 16 May 2024 18:00:14 -0500 Subject: [PATCH] docs: fix errors and table formatting in notebook (#21696) There are 2 issues fixed here: * In the notebook pandas dataframes are formatted as HTML in the cells. On the documentation site the renderer that converts notebooks incorrectly displays the raw HTML. I can't find any examples of where this is working and so I am formatting the dataframes as text. * Some incorrect table names were referenced resulting in errors. --- docs/docs/integrations/chat/kinetica.ipynb | 366 ++++----------------- 1 file changed, 62 insertions(+), 304 deletions(-) diff --git a/docs/docs/integrations/chat/kinetica.ipynb b/docs/docs/integrations/chat/kinetica.ipynb index 4482efcb55a..36bb049e782 100644 --- a/docs/docs/integrations/chat/kinetica.ipynb +++ b/docs/docs/integrations/chat/kinetica.ipynb @@ -54,18 +54,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Note: you may need to restart the kernel to use updated packages.\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], + "outputs": [], "source": [ "# Install Langchain community and core packages\n", "%pip install --upgrade --quiet langchain-core langchain-community\n", @@ -123,126 +114,37 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
usernamenamesexaddressmailbirthdate
id
0eduardo69Haley BeckF59836 Carla Causeway Suite 939\\nPort Eugene, I...meltondenise@yahoo.com1997-11-23
1lbarreraJoshua StephensM3108 Christina Forges\\nPort Timothychester, KY...erica80@hotmail.com1924-07-19
2bburtonPaula KaiserFUnit 7405 Box 3052\\nDPO AE 09858timothypotts@gmail.com1933-11-20
3melissa49Wendy ReeseF6408 Christopher Hill Apt. 459\\nNew Benjamin, ...dadams@gmail.com1988-10-11
4melissacarterManuel RiosM2241 Bell Gardens Suite 723\\nScottside, CA 38463williamayala@gmail.com1931-03-04
\n", - "
" - ], - "text/plain": [ - " username name sex \\\n", - "id \n", - "0 eduardo69 Haley Beck F \n", - "1 lbarrera Joshua Stephens M \n", - "2 bburton Paula Kaiser F \n", - "3 melissa49 Wendy Reese F \n", - "4 melissacarter Manuel Rios M \n", - "\n", - " address mail \\\n", - "id \n", - "0 59836 Carla Causeway Suite 939\\nPort Eugene, I... meltondenise@yahoo.com \n", - "1 3108 Christina Forges\\nPort Timothychester, KY... erica80@hotmail.com \n", - "2 Unit 7405 Box 3052\\nDPO AE 09858 timothypotts@gmail.com \n", - "3 6408 Christopher Hill Apt. 459\\nNew Benjamin, ... dadams@gmail.com \n", - "4 2241 Bell Gardens Suite 723\\nScottside, CA 38463 williamayala@gmail.com \n", - "\n", - " birthdate \n", - "id \n", - "0 1997-11-23 \n", - "1 1924-07-19 \n", - "2 1933-11-20 \n", - "3 1988-10-11 \n", - "4 1931-03-04 " - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + " username name sex \\\n", + "id \n", + "0 eduardo69 Haley Beck F \n", + "1 lbarrera Joshua Stephens M \n", + "2 bburton Paula Kaiser F \n", + "3 melissa49 Wendy Reese F \n", + "4 melissacarter Manuel Rios M \n", + "\n", + " address mail \\\n", + "id \n", + "0 59836 Carla Causeway Suite 939\\nPort Eugene, I... meltondenise@yahoo.com \n", + "1 3108 Christina Forges\\nPort Timothychester, KY... erica80@hotmail.com \n", + "2 Unit 7405 Box 3052\\nDPO AE 09858 timothypotts@gmail.com \n", + "3 6408 Christopher Hill Apt. 459\\nNew Benjamin, ... dadams@gmail.com \n", + "4 2241 Bell Gardens Suite 723\\nScottside, CA 38463 williamayala@gmail.com \n", + "\n", + " birthdate \n", + "id \n", + "0 1997-12-01 \n", + "1 1924-07-27 \n", + "2 1933-11-28 \n", + "3 1988-10-19 \n", + "4 1931-03-12 \n" + ] } ], "source": [ @@ -263,7 +165,7 @@ "\n", "\n", "load_df = pd.DataFrame.from_records(data=profile_gen(100), index=\"id\")\n", - "load_df.head()" + "print(load_df.head())" ] }, { @@ -279,85 +181,17 @@ "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
nametypeproperties
0usernamestring[char32]
1namestring[char32]
2sexstring[char1]
3addressstring[char64]
4mailstring[char32]
5birthdatelong[timestamp]
\n", - "
" - ], - "text/plain": [ - " name type properties\n", - "0 username string [char32]\n", - "1 name string [char32]\n", - "2 sex string [char1]\n", - "3 address string [char64]\n", - "4 mail string [char32]\n", - "5 birthdate long [timestamp]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + " name type properties\n", + "0 username string [char32]\n", + "1 name string [char32]\n", + "2 sex string [char2]\n", + "3 address string [char64]\n", + "4 mail string [char32]\n", + "5 birthdate long [timestamp]\n" + ] } ], "source": [ @@ -372,7 +206,7 @@ ")\n", "\n", "# See the Kinetica column types\n", - "gpudb_table.type_as_df()" + "print(gpudb_table.type_as_df())" ] }, { @@ -394,10 +228,7 @@ { "data": { "text/plain": [ - "{'status': 'OK',\n", - " 'message': '',\n", - " 'data_type': 'execute_sql_response',\n", - " 'response_time': 0.0148}" + "1" ] }, "execution_count": 4, @@ -408,34 +239,23 @@ "source": [ "# create an LLM context for the table.\n", "\n", - "from gpudb import GPUdbException\n", - "\n", "sql = f\"\"\"\n", "CREATE OR REPLACE CONTEXT {kinetica_ctx}\n", "(\n", - " TABLE = demo.test_profiles\n", + " TABLE = {table_name}\n", " COMMENT = 'Contains user profiles.'\n", "),\n", "(\n", " SAMPLES = (\n", " 'How many male users are there?' = \n", " 'select count(1) as num_users\n", - " from demo.test_profiles\n", + " from {table_name}\n", " where sex = ''M'';')\n", ")\n", "\"\"\"\n", "\n", - "\n", - "def _check_error(response: dict) -> None:\n", - " status = response[\"status_info\"][\"status\"]\n", - " if status != \"OK\":\n", - " message = response[\"status_info\"][\"message\"]\n", - " raise GPUdbException(\"[%s]: %s\" % (status, message))\n", - "\n", - "\n", - "response = kinetica_llm.kdbc.execute_sql(sql)\n", - "_check_error(response)\n", - "response[\"status_info\"]" + "count_affected = kinetica_llm.kdbc.execute(sql)\n", + "count_affected" ] }, { @@ -462,16 +282,16 @@ "text": [ "================================\u001b[1m System Message \u001b[0m================================\n", "\n", - "CREATE TABLE demo.test_profiles AS\n", + "CREATE TABLE demo.user_profiles AS\n", "(\n", " username VARCHAR (32) NOT NULL,\n", " name VARCHAR (32) NOT NULL,\n", - " sex VARCHAR (1) NOT NULL,\n", + " sex VARCHAR (2) NOT NULL,\n", " address VARCHAR (64) NOT NULL,\n", " mail VARCHAR (32) NOT NULL,\n", " birthdate TIMESTAMP NOT NULL\n", ");\n", - "COMMENT ON TABLE demo.test_profiles IS 'Contains user profiles.';\n", + "COMMENT ON TABLE demo.user_profiles IS 'Contains user profiles.';\n", "\n", "================================\u001b[1m Human Message \u001b[0m=================================\n", "\n", @@ -480,7 +300,7 @@ "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "\n", "select count(1) as num_users\n", - " from demo.test_profiles\n", + " from demo.user_profiles\n", " where sex = 'M';\n", "\n", "================================\u001b[1m Human Message \u001b[0m=================================\n", @@ -545,78 +365,16 @@ "output_type": "stream", "text": [ "SQL: SELECT username, name\n", - " FROM demo.test_profiles\n", + " FROM demo.user_profiles\n", " WHERE sex = 'F'\n", - " ORDER BY username;\n" + " ORDER BY username;\n", + " username name\n", + "0 alexander40 Tina Ramirez\n", + "1 bburton Paula Kaiser\n", + "2 brian12 Stefanie Williams\n", + "3 brownanna Jennifer Rowe\n", + "4 carl19 Amanda Potts\n" ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
usernamename
0alexander40Tina Ramirez
1bburtonPaula Kaiser
2brian12Stefanie Williams
3brownannaJennifer Rowe
4carl19Amanda Potts
\n", - "
" - ], - "text/plain": [ - " username name\n", - "0 alexander40 Tina Ramirez\n", - "1 bburton Paula Kaiser\n", - "2 brian12 Stefanie Williams\n", - "3 brownanna Jennifer Rowe\n", - "4 carl19 Amanda Potts" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -626,7 +384,7 @@ ")\n", "\n", "print(f\"SQL: {response.sql}\")\n", - "response.dataframe.head()" + "print(response.dataframe.head())" ] } ], @@ -646,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.8.19" } }, "nbformat": 4,