|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "055c1fab-abcb-40df-bcd1-20b60d2273ce", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "### Configure the Model for Strands Agents\n", |
| 9 | + "\n", |
| 10 | + "<div class=\"alert alert-block alert-info\">\n", |
| 11 | + "\t⚠️ <b>Important:</b> ⚠️</br> To use <b>Amazon SageMaker AI</b>,Run this notebook only when you intend to execute Strands workshop under <code>4-frameworks/strands-agents</code>and no other workshop \n", |
| 12 | + "</div>" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "id": "e05d69d6", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "# Installing Dependencies\n", |
| 21 | + "\n", |
| 22 | + "Please install the dependencies before proceeding with the rest of the workshop." |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": null, |
| 28 | + "id": "d64ef10b", |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "%%capture\n", |
| 33 | + "import warnings\n", |
| 34 | + "warnings.filterwarnings(\"ignore\")\n", |
| 35 | + "%pip uninstall -q -y autogluon-multimodal autogluon-timeseries autogluon-features autogluon-common autogluon-core\n", |
| 36 | + "%pip install -Uq -r requirements-strands.txt\n", |
| 37 | + "from IPython import get_ipython\n", |
| 38 | + "get_ipython().kernel.do_shutdown(True)\n" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "id": "6795ccde-9d4a-4488-8fd2-8a0747801392", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "# Create knowledge base\n", |
| 47 | + "\n", |
| 48 | + "### We will create a knowledge base with s3 as vector store. We will leverage this knowledge base in our lab to query and retreive information by agents. " |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "code", |
| 53 | + "execution_count": null, |
| 54 | + "id": "8c033499-7d03-4fbe-be60-5218aaafd6b1", |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "!python ../4-frameworks/strands-agents/utils/create_kb.py" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "markdown", |
| 63 | + "id": "2565ea70-8a18-451f-8a7f-0662c76fba61", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "# Clean up unwanted directories" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "id": "2fa8b666-7fe1-419c-b2fa-a55a8985226e", |
| 73 | + "metadata": { |
| 74 | + "execution": { |
| 75 | + "iopub.execute_input": "2025-08-30T01:04:58.333733Z", |
| 76 | + "iopub.status.busy": "2025-08-30T01:04:58.333324Z", |
| 77 | + "iopub.status.idle": "2025-08-30T01:04:59.189553Z", |
| 78 | + "shell.execute_reply": "2025-08-30T01:04:59.188738Z", |
| 79 | + "shell.execute_reply.started": "2025-08-30T01:04:58.333705Z" |
| 80 | + } |
| 81 | + }, |
| 82 | + "outputs": [], |
| 83 | + "source": [ |
| 84 | + "%%bash\n", |
| 85 | + "set -eux\n", |
| 86 | + "\n", |
| 87 | + "# Directory to clone the repo into\n", |
| 88 | + "REPO_DIR=\"/home/sagemaker-user/generative-ai-on-amazon-sagemaker\"\n", |
| 89 | + "\n", |
| 90 | + "# Clone the repo if it doesn't exist, otherwise pull the latest\n", |
| 91 | + "if [ -d \"$REPO_DIR\" ]; then\n", |
| 92 | + " cd \"$REPO_DIR\"\n", |
| 93 | + " git pull\n", |
| 94 | + "else\n", |
| 95 | + " git clone https://github.com/aws-samples/generative-ai-on-amazon-sagemaker.git \"$REPO_DIR\"\n", |
| 96 | + " cd \"$REPO_DIR\"\n", |
| 97 | + "fi\n", |
| 98 | + "\n", |
| 99 | + "# Define directories to keep (relative to repo root)\n", |
| 100 | + "keep_dirs=(\n", |
| 101 | + " \"workshops/diy-agents-with-sagemaker-and-bedrock/4-frameworks/strands-agents\"\n", |
| 102 | + " \"workshops/diy-agents-with-sagemaker-and-bedrock/0-setup\"\n", |
| 103 | + " \"workshops/diy-agents-with-sagemaker-and-bedrock/99-use-cases/sagemaker-endpoint-as-tool\"\n", |
| 104 | + ")\n", |
| 105 | + "\n", |
| 106 | + "# Copy keep_dirs to a temp location\n", |
| 107 | + "mkdir -p /tmp/keep_dirs\n", |
| 108 | + "for d in \"${keep_dirs[@]}\"; do\n", |
| 109 | + " if [ -d \"$d\" ]; then\n", |
| 110 | + " mkdir -p \"/tmp/keep_dirs/$(dirname \"$d\")\"\n", |
| 111 | + " mv \"$d\" \"/tmp/keep_dirs/$d\"\n", |
| 112 | + " fi\n", |
| 113 | + "done\n", |
| 114 | + "\n", |
| 115 | + "# Delete everything in repo except .git\n", |
| 116 | + "find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +\n", |
| 117 | + "\n", |
| 118 | + "# Move keep_dirs back\n", |
| 119 | + "for d in \"${keep_dirs[@]}\"; do\n", |
| 120 | + " mkdir -p \"$(dirname \"$d\")\"\n", |
| 121 | + " mv \"/tmp/keep_dirs/$d\" \"$d\"\n", |
| 122 | + "done\n", |
| 123 | + "\n", |
| 124 | + "rm -rf /tmp/keep_dirs\n", |
| 125 | + "\n", |
| 126 | + "# Result: Only the three requested folders (and their parent paths) remain in the repo.\n" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": null, |
| 132 | + "id": "a97a1b41-d1f1-4454-887b-1bf146933a0f", |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [], |
| 135 | + "source": [] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "Python 3 (ipykernel)", |
| 141 | + "language": "python", |
| 142 | + "name": "python3" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "codemirror_mode": { |
| 146 | + "name": "ipython", |
| 147 | + "version": 3 |
| 148 | + }, |
| 149 | + "file_extension": ".py", |
| 150 | + "mimetype": "text/x-python", |
| 151 | + "name": "python", |
| 152 | + "nbconvert_exporter": "python", |
| 153 | + "pygments_lexer": "ipython3", |
| 154 | + "version": "3.12.9" |
| 155 | + } |
| 156 | + }, |
| 157 | + "nbformat": 4, |
| 158 | + "nbformat_minor": 5 |
| 159 | +} |
0 commit comments