From ca53b584314ae1c8f96d4d1844e30a76beee7d81 Mon Sep 17 00:00:00 2001 From: Holt Skinner <13262395+holtskinner@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:46:11 -0600 Subject: [PATCH] fix: Updates to Code Execution Notebook (#1604) - Change Code output to use Language syntax highlighting --- .../code-execution/intro_code_execution.ipynb | 643 +++++++++++------- 1 file changed, 404 insertions(+), 239 deletions(-) diff --git a/gemini/code-execution/intro_code_execution.ipynb b/gemini/code-execution/intro_code_execution.ipynb index 1dbdca00180..9641f0757fd 100644 --- a/gemini/code-execution/intro_code_execution.ipynb +++ b/gemini/code-execution/intro_code_execution.ipynb @@ -48,11 +48,6 @@ " \n", " \n", " \n", - " \n", - " \"BigQuery
Open in BigQuery Studio\n", - "
\n", - " \n", - " \n", " \n", " \"GitHub
View on GitHub\n", "
\n", @@ -142,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "id": "tFy3H3aPgx12" }, @@ -189,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "id": "JbrnA9yv3zMC" }, @@ -197,9 +192,9 @@ "source": [ "import os\n", "\n", - "from IPython.display import Markdown, display\n", + "from IPython.display import HTML, Markdown, display\n", "from google import genai\n", - "from google.genai.types import GenerateContentConfig, Tool" + "from google.genai.types import GenerateContentConfig, Tool, ToolCodeExecution" ] }, { @@ -234,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "id": "Nqwi-5ufWp_B" }, @@ -249,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": { "id": "3Ab5NQwr4B8j" }, @@ -269,17 +264,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": { "id": "Y2e1lK_f_YWN" }, "outputs": [], "source": [ - "from IPython.display import HTML, Markdown\n", - "\n", - "\n", "# Modify CSS to display the results more clearly in Colab\n", - "def set_css_in_cell_output(unused):\n", + "def set_css_in_cell_output():\n", " display(\n", " HTML(\n", " \"\"\"" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "MODEL_ID = \"gemini-2.0-flash-exp\" # @param {type: \"string\"}" ] @@ -372,41 +335,13 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { "id": "BFxIcGkxbq3_" }, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ - "code_execution_tool = Tool(code_execution={})" + "code_execution_tool = Tool(code_execution=ToolCodeExecution())" ] }, { @@ -422,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { "id": "b52qMx0IGA0K" }, @@ -484,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "id": "J5mcXw6ZraLS" }, @@ -520,7 +455,7 @@ "data": { "text/markdown": [ "\n", - "```\n", + "```py\n", "\n", "def is_prime(n):\n", " if n <= 1:\n", @@ -562,7 +497,7 @@ " display(\n", " Markdown(\n", " f\"\"\"\n", - "```\n", + "```py\n", "{part.executable_code.code}\n", "```\n", "\"\"\"\n", @@ -583,7 +518,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "id": "J891OBjc4xn9" }, @@ -618,7 +553,8 @@ { "data": { "text/markdown": [ - "sum_of_primes=5117\n" + "`sum_of_primes=5117\n", + "`" ], "text/plain": [ "" @@ -639,7 +575,7 @@ "source": [ "for part in response.candidates[0].content.parts:\n", " if part.code_execution_result:\n", - " display(Markdown(part.code_execution_result.output))\n", + " display(Markdown(f\"`{part.code_execution_result.output}`\"))\n", " print(\"\\nOutcome:\", part.code_execution_result.outcome)" ] }, @@ -649,7 +585,7 @@ "id": "5u_XuZlMnH9S" }, "source": [ - "Great! Now you have the answer (5117) as well as the generated (and verified via execution!) Python code.\n", + "Great! Now you have the answer (`5117`) as well as the generated (and verified via execution!) Python code.\n", "\n", "At this point in your application, you would save the output code, result, or outcome and display it to the end-user or use it downstream in your application." ] @@ -669,7 +605,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "id": "puL91bq7tirC" }, @@ -723,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "id": "8iyq5sKCtstH" }, @@ -759,7 +695,7 @@ "source": [ "response = chat.send_message(\n", " \"\"\"Generate code that creates sample time series\n", - "data of temperature vs. time in a test furnace. Add noise to the data. Output\n", + "data of temperature vs. time in a test furnace. Add noise to the data. Output\n", "a sample of 10 data points from the time series data.\"\"\"\n", ")" ] @@ -775,7 +711,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "id": "8pjwEGzft29N" }, @@ -811,28 +747,28 @@ "data": { "text/markdown": [ "\n", - "```\n", + "```py\n", "\n", "import numpy as np\n", "\n", - "# 1. Define Time Range\n", - "time = np.linspace(0, 10, 100) # 100 points from 0 to 10 seconds\n", + "# 1. Define time range\n", + "time = np.linspace(0, 100, 1000) # 1000 points from 0 to 100 seconds\n", "\n", - "# 2. Generate Base Temperature Data (linear increase)\n", - "base_temp = 20 + 5 * time # Start at 20 degrees, increase by 5 degrees per second\n", + "# 2. Create a base temperature profile (example: increasing temperature with a curve)\n", + "base_temp = 25 + 50 * (1 - np.exp(-time / 30)) # Starts at 25 and increases to 75\n", "\n", - "# 3. Add Noise\n", - "noise = np.random.normal(0, 2, len(time)) # Gaussian noise with mean 0, std dev 2\n", - "noisy_temp = base_temp + noise\n", + "# 3. Add noise\n", + "noise = np.random.normal(0, 2, len(time)) # Gaussian noise with mean 0 and std dev 2\n", + "temperature = base_temp + noise\n", "\n", - "# 4. Output Sample\n", + "# 4. Output 10 data points\n", "sample_indices = np.linspace(0, len(time) - 1, 10, dtype=int)\n", "sample_time = time[sample_indices]\n", - "sample_temp = noisy_temp[sample_indices]\n", + "sample_temperature = temperature[sample_indices]\n", "\n", "print(\"Sample Time Series Data (Time, Temperature):\")\n", - "for t, temp in zip(sample_time, sample_temp):\n", - " print(f\"Time: {t:.2f} s, Temperature: {temp:.2f} °C\")\n", + "for t, temp in zip(sample_time, sample_temperature):\n", + " print(f\"({t:.2f}, {temp:.2f})\")\n", "\n", "```\n" ], @@ -846,17 +782,18 @@ { "data": { "text/markdown": [ - "Sample Time Series Data (Time, Temperature):\n", - "Time: 0.00 s, Temperature: 21.10 °C\n", - "Time: 1.11 s, Temperature: 27.38 °C\n", - "Time: 2.22 s, Temperature: 32.54 °C\n", - "Time: 3.33 s, Temperature: 35.23 °C\n", - "Time: 4.44 s, Temperature: 44.09 °C\n", - "Time: 5.56 s, Temperature: 49.99 °C\n", - "Time: 6.67 s, Temperature: 52.68 °C\n", - "Time: 7.78 s, Temperature: 59.13 °C\n", - "Time: 8.89 s, Temperature: 64.07 °C\n", - "Time: 10.00 s, Temperature: 66.55 °C\n" + "`Sample Time Series Data (Time, Temperature):\n", + "(0.00, 24.66)\n", + "(11.11, 41.32)\n", + "(22.22, 48.47)\n", + "(33.33, 59.90)\n", + "(44.44, 63.03)\n", + "(55.56, 69.59)\n", + "(66.67, 68.61)\n", + "(77.78, 71.45)\n", + "(88.89, 72.76)\n", + "(100.00, 75.88)\n", + "`" ], "text/plain": [ "" @@ -880,14 +817,14 @@ " display(\n", " Markdown(\n", " f\"\"\"\n", - "```\n", + "```py\n", "{part.executable_code.code}\n", "```\n", "\"\"\"\n", " )\n", " )\n", " if part.code_execution_result:\n", - " display(Markdown(part.code_execution_result.output))\n", + " display(Markdown(f\"`{part.code_execution_result.output}`\"))\n", " print(\"\\nOutcome:\", part.code_execution_result.outcome)" ] }, @@ -902,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "id": "alR_tq3pss7j" }, @@ -952,7 +889,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": { "id": "uMXRpE0NtRYC" }, @@ -988,45 +925,31 @@ "data": { "text/markdown": [ "\n", - "```\n", + "```py\n", "\n", "import numpy as np\n", + "import pandas as pd\n", "\n", - "def moving_average(data, window_size):\n", - " \"\"\"Calculates the moving average of a 1D array.\"\"\"\n", - " if window_size > len(data):\n", - " raise ValueError(\"Window size cannot be larger than the data length.\")\n", - " \n", - " weights = np.repeat(1.0, window_size) / window_size\n", - " return np.convolve(data, weights, 'valid')\n", - "\n", - "# 1. Define Time Range\n", - "time = np.linspace(0, 10, 100) # 100 points from 0 to 10 seconds\n", - "\n", - "# 2. Generate Base Temperature Data (linear increase)\n", - "base_temp = 20 + 5 * time # Start at 20 degrees, increase by 5 degrees per second\n", - "\n", - "# 3. Add Noise\n", - "noise = np.random.normal(0, 2, len(time)) # Gaussian noise with mean 0, std dev 2\n", - "noisy_temp = base_temp + noise\n", + "# 1. Generate time series data (same as before)\n", + "time = np.linspace(0, 100, 1000)\n", + "base_temp = 25 + 50 * (1 - np.exp(-time / 30))\n", + "noise = np.random.normal(0, 2, len(time))\n", + "temperature = base_temp + noise\n", "\n", - "# 4. Calculate Moving Average\n", - "window_size = 5\n", - "smoothed_temp = moving_average(noisy_temp, window_size)\n", + "# 2. Apply a moving average filter\n", + "window_size = 20 # Choose a window size for the moving average\n", + "smoothed_temperature = pd.Series(temperature).rolling(window=window_size, min_periods=1).mean().to_numpy()\n", "\n", - "# Adjust time array to match the length of smoothed data\n", - "smoothed_time = time[window_size - 1:]\n", - "\n", - "# 5. Output Sample\n", - "sample_indices = np.linspace(0, len(smoothed_time) - 1, 10, dtype=int)\n", - "sample_time = smoothed_time[sample_indices]\n", - "sample_noisy_temp = noisy_temp[window_size - 1:][sample_indices]\n", - "sample_smoothed_temp = smoothed_temp[sample_indices]\n", "\n", + "# 3. Output 10 data points\n", + "sample_indices = np.linspace(0, len(time) - 1, 10, dtype=int)\n", + "sample_time = time[sample_indices]\n", + "sample_temperature = temperature[sample_indices]\n", + "sample_smoothed_temperature = smoothed_temperature[sample_indices]\n", "\n", - "print(\"Sample Time Series Data (Time, Noisy Temp, Smoothed Temp):\")\n", - "for t, noisy_temp, smoothed_temp in zip(sample_time, sample_noisy_temp, sample_smoothed_temp):\n", - " print(f\"Time: {t:.2f} s, Noisy Temp: {noisy_temp:.2f} °C, Smoothed Temp: {smoothed_temp:.2f} °C\")\n", + "print(\"Sample Time Series Data (Time, Temperature, Smoothed Temperature):\")\n", + "for t, temp, smooth_temp in zip(sample_time, sample_temperature, sample_smoothed_temperature):\n", + " print(f\"({t:.2f}, {temp:.2f}, {smooth_temp:.2f})\")\n", "\n", "```\n" ], @@ -1040,17 +963,18 @@ { "data": { "text/markdown": [ - "Sample Time Series Data (Time, Noisy Temp, Smoothed Temp):\n", - "Time: 0.40 s, Noisy Temp: 24.24 °C, Smoothed Temp: 20.87 °C\n", - "Time: 1.41 s, Noisy Temp: 25.06 °C, Smoothed Temp: 25.35 °C\n", - "Time: 2.53 s, Noisy Temp: 35.70 °C, Smoothed Temp: 31.72 °C\n", - "Time: 3.54 s, Noisy Temp: 37.72 °C, Smoothed Temp: 37.53 °C\n", - "Time: 4.65 s, Noisy Temp: 42.47 °C, Smoothed Temp: 41.59 °C\n", - "Time: 5.66 s, Noisy Temp: 46.74 °C, Smoothed Temp: 47.52 °C\n", - "Time: 6.77 s, Noisy Temp: 51.56 °C, Smoothed Temp: 52.91 °C\n", - "Time: 7.78 s, Noisy Temp: 59.30 °C, Smoothed Temp: 57.67 °C\n", - "Time: 8.89 s, Noisy Temp: 63.41 °C, Smoothed Temp: 62.32 °C\n", - "Time: 10.00 s, Noisy Temp: 69.06 °C, Smoothed Temp: 69.32 °C\n" + "`Sample Time Series Data (Time, Temperature, Smoothed Temperature):\n", + "(0.00, 26.57, 26.57)\n", + "(11.11, 39.02, 39.20)\n", + "(22.22, 51.49, 50.66)\n", + "(33.33, 58.64, 59.27)\n", + "(44.44, 63.01, 63.42)\n", + "(55.56, 68.41, 67.38)\n", + "(66.67, 67.22, 69.29)\n", + "(77.78, 70.09, 70.99)\n", + "(88.89, 71.91, 71.57)\n", + "(100.00, 72.73, 73.23)\n", + "`" ], "text/plain": [ "" @@ -1074,14 +998,14 @@ " display(\n", " Markdown(\n", " f\"\"\"\n", - "```\n", + "```py\n", "{part.executable_code.code}\n", "```\n", "\"\"\"\n", " )\n", " )\n", " if part.code_execution_result:\n", - " display(Markdown(part.code_execution_result.output))\n", + " display(Markdown(f\"`{part.code_execution_result.output}`\"))\n", " print(\"\\nOutcome:\", part.code_execution_result.outcome)" ] }, @@ -1096,7 +1020,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": { "id": "dmhPzmP8tywL" }, @@ -1146,7 +1070,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "id": "hIsMH3fPuKr5" }, @@ -1182,62 +1106,43 @@ "data": { "text/markdown": [ "\n", - "```\n", + "```py\n", "\n", "import numpy as np\n", - "\n", - "def moving_average(data, window_size):\n", - " \"\"\"Calculates the moving average of a 1D array.\"\"\"\n", - " if window_size > len(data):\n", - " raise ValueError(\"Window size cannot be larger than the data length.\")\n", - " \n", - " weights = np.repeat(1.0, window_size) / window_size\n", - " return np.convolve(data, weights, 'valid')\n", - "\n", - "# 1. Define Time Range\n", - "time = np.linspace(0, 10, 100) # 100 points from 0 to 10 seconds\n", - "\n", - "# 2. Generate Base Temperature Data (linear increase)\n", - "base_temp = 20 + 5 * time # Start at 20 degrees, increase by 5 degrees per second\n", - "\n", - "# 3. Add Noise\n", - "noise = np.random.normal(0, 2, len(time)) # Gaussian noise with mean 0, std dev 2\n", - "noisy_temp = base_temp + noise\n", - "\n", - "# 4. Calculate Moving Average\n", - "window_size = 5\n", - "smoothed_temp = moving_average(noisy_temp, window_size)\n", - "\n", - "# Adjust time array to match the length of smoothed data\n", - "smoothed_time = time[window_size - 1:]\n", - "\n", - "# 5. Calculate Descriptive Statistics\n", - "noisy_mean = np.mean(noisy_temp)\n", - "noisy_std = np.std(noisy_temp)\n", - "noisy_min = np.min(noisy_temp)\n", - "noisy_max = np.max(noisy_temp)\n", - "\n", - "smoothed_mean = np.mean(smoothed_temp)\n", - "smoothed_std = np.std(smoothed_temp)\n", - "smoothed_min = np.min(smoothed_temp)\n", - "smoothed_max = np.max(smoothed_temp)\n", - "\n", - "\n", - "# 6. Output Statistics\n", + "import pandas as pd\n", + "\n", + "# 1. Generate time series data (same as before)\n", + "time = np.linspace(0, 100, 1000)\n", + "base_temp = 25 + 50 * (1 - np.exp(-time / 30))\n", + "noise = np.random.normal(0, 2, len(time))\n", + "temperature = base_temp + noise\n", + "\n", + "# 2. Apply a moving average filter\n", + "window_size = 20\n", + "smoothed_temperature = pd.Series(temperature).rolling(window=window_size, min_periods=1).mean().to_numpy()\n", + "\n", + "# 3. Calculate descriptive statistics\n", + "def calculate_stats(data, name):\n", + " stats = {\n", + " f'{name}_mean': np.mean(data),\n", + " f'{name}_std': np.std(data),\n", + " f'{name}_min': np.min(data),\n", + " f'{name}_max': np.max(data),\n", + " f'{name}_25th': np.percentile(data, 25),\n", + " f'{name}_50th': np.percentile(data, 50),\n", + " f'{name}_75th': np.percentile(data, 75)\n", + " }\n", + " return stats\n", + "\n", + "noisy_stats = calculate_stats(temperature, \"noisy_temp\")\n", + "smoothed_stats = calculate_stats(smoothed_temperature, \"smoothed_temp\")\n", + "\n", + "# 4. Output the statistics\n", "print(\"Descriptive Statistics:\")\n", - "print(\"--------------------------------------------------\")\n", - "print(\"Noisy Temperature Data:\")\n", - "print(f\" Mean: {noisy_mean:.2f} °C\")\n", - "print(f\" Standard Deviation: {noisy_std:.2f} °C\")\n", - "print(f\" Minimum: {noisy_min:.2f} °C\")\n", - "print(f\" Maximum: {noisy_max:.2f} °C\")\n", - "print(\"--------------------------------------------------\")\n", - "print(\"Smoothed Temperature Data:\")\n", - "print(f\" Mean: {smoothed_mean:.2f} °C\")\n", - "print(f\" Standard Deviation: {smoothed_std:.2f} °C\")\n", - "print(f\" Minimum: {smoothed_min:.2f} °C\")\n", - "print(f\" Maximum: {smoothed_max:.2f} °C\")\n", - "print(\"--------------------------------------------------\")\n", + "for key, value in noisy_stats.items():\n", + " print(f\"{key}: {value:.2f}\")\n", + "for key, value in smoothed_stats.items():\n", + " print(f\"{key}: {value:.2f}\")\n", "\n", "```\n" ], @@ -1251,20 +1156,22 @@ { "data": { "text/markdown": [ - "Descriptive Statistics:\n", - "--------------------------------------------------\n", - "Noisy Temperature Data:\n", - " Mean: 44.80 °C\n", - " Standard Deviation: 14.48 °C\n", - " Minimum: 17.34 °C\n", - " Maximum: 70.30 °C\n", - "--------------------------------------------------\n", - "Smoothed Temperature Data:\n", - " Mean: 44.84 °C\n", - " Standard Deviation: 13.84 °C\n", - " Minimum: 21.89 °C\n", - " Maximum: 67.61 °C\n", - "--------------------------------------------------\n" + "`Descriptive Statistics:\n", + "noisy_temp_mean: 60.44\n", + "noisy_temp_std: 13.05\n", + "noisy_temp_min: 21.50\n", + "noisy_temp_max: 78.02\n", + "noisy_temp_25th: 52.83\n", + "noisy_temp_50th: 65.42\n", + "noisy_temp_75th: 70.60\n", + "smoothed_temp_mean: 59.99\n", + "smoothed_temp_std: 13.26\n", + "smoothed_temp_min: 24.71\n", + "smoothed_temp_max: 73.62\n", + "smoothed_temp_25th: 52.35\n", + "smoothed_temp_50th: 65.58\n", + "smoothed_temp_75th: 70.54\n", + "`" ], "text/plain": [ "" @@ -1288,14 +1195,14 @@ " display(\n", " Markdown(\n", " f\"\"\"\n", - "```\n", + "```py\n", "{part.executable_code.code}\n", "```\n", "\"\"\"\n", " )\n", " )\n", " if part.code_execution_result:\n", - " display(Markdown(part.code_execution_result.output))\n", + " display(Markdown(f\"`{part.code_execution_result.output}`\"))\n", " print(\"\\nOutcome:\", part.code_execution_result.outcome)" ] }, @@ -1323,7 +1230,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": { "id": "gTNMMLkNu5JH" }, @@ -1630,7 +1537,7 @@ "data": { "text/markdown": [ "\n", - "```\n", + "```py\n", "\n", "import random\n", "\n", @@ -1693,9 +1600,9 @@ "text/markdown": [ "\n", "```\n", - "random_names=['Noah', 'Bob', 'Tom', 'Quinn', 'Jack', 'Ryan', 'Henry', 'Eve', 'Kate', 'Liam', 'Ivy', 'Ivy', 'Eve', 'Henry', 'Liam', 'Jack', 'Bob', 'Frank', 'Grace', 'Kate']\n", - "count_of_names_with_a=10\n", - "names_with_a=['Noah', 'Jack', 'Ryan', 'Kate', 'Liam', 'Liam', 'Jack', 'Frank', 'Grace', 'Kate']\n", + "random_names=['Liam', 'Sophia', 'David', 'Kate', 'Olivia', 'Tom', 'David', 'Olivia', 'Charlie', 'Grace', 'Olivia', 'Alice', 'David', 'Jack', 'Peter', 'Ivy', 'Charlie', 'Tom', 'Jack', 'Eve']\n", + "count_of_names_with_a=15\n", + "names_with_a=['Liam', 'Sophia', 'David', 'Kate', 'Olivia', 'David', 'Olivia', 'Charlie', 'Grace', 'Olivia', 'Alice', 'David', 'Jack', 'Charlie', 'Jack']\n", "\n", "```\n" ], @@ -1706,6 +1613,264 @@ "metadata": {}, "output_type": "display_data" }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "Okay" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + ", here's the output:\n", + "\n", + "The original list of 20 random" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + " names is: `['Liam', 'Sophia', 'David', 'Kate'," + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + " 'Olivia', 'Tom', 'David', 'Olivia', 'Charlie', 'Grace', 'Olivia', 'Alice', 'David', 'Jack', 'Peter" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "', 'Ivy', 'Charlie', 'Tom', 'Jack', 'Eve']`\n", + "\n", + "The number of names containing the letter 'a' is: 1" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "5\n", + "\n", + "The list of names containing the letter 'a' is: `['Liam', 'Sophia', 'David', 'Kate', 'Olivia', 'David', 'Olivia', 'Charlie', 'Grace', 'Olivia', 'Alice'," + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "---" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "#### Natural language stream" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + " 'David', 'Jack', 'Charlie', 'Jack']`\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "data": { "text/markdown": [ @@ -1744,7 +1909,7 @@ " display(\n", " Markdown(\n", " f\"\"\"\n", - "```\n", + "```py\n", "{part.executable_code.code}\n", "```\n", "\"\"\"\n",