From da0759de5375434071792cf8f050845e14443c54 Mon Sep 17 00:00:00 2001 From: karsols Date: Thu, 8 May 2025 16:57:06 +0200 Subject: [PATCH] added python cells to notebook search --- .../week2-toolcall-to-course-material.ipynb | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/week2/community-contributions/week2-toolcall-to-course-material.ipynb b/week2/community-contributions/week2-toolcall-to-course-material.ipynb index 5130dcd..bdf17bf 100644 --- a/week2/community-contributions/week2-toolcall-to-course-material.ipynb +++ b/week2/community-contributions/week2-toolcall-to-course-material.ipynb @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "id": "7f02f5c4", "metadata": {}, "outputs": [], @@ -117,12 +117,20 @@ "\n", " data = json.loads(notebook_path.read_text())\n", " \n", - " # Get text from all markdown cells\n", - " markdown_cells = [\n", - " cell[\"source\"] for cell in data.get(\"cells\", []) \n", - " if cell.get(\"cell_type\") == \"markdown\"\n", - " ]\n", - " text = \"\\n\\n\".join(\"\".join(cell) for cell in markdown_cells).strip()\n", + " # Include both markdown and code if available\n", + " cells = []\n", + " for cell in data.get(\"cells\", []):\n", + " if cell.get(\"cell_type\") == \"markdown\":\n", + " cells.append(\"\".join(cell[\"source\"]))\n", + " elif cell.get(\"cell_type\") == \"code\":\n", + " code = \"\".join(cell[\"source\"])\n", + " cells.append(f\"```python\\n{code}\\n```\")\n", + " if \"outputs\" in cell:\n", + " for output in cell[\"outputs\"]:\n", + " if \"text\" in output:\n", + " cells.append(\"\".join(output[\"text\"]))\n", + " \n", + " text = \"\\n\\n\".join(cells).strip()\n", " \n", " if text:\n", " self.docs.append({\n",