|
11 | 11 | "\n", |
12 | 12 | "# Llama Stack - Building AI Applications\n", |
13 | 13 | "\n", |
14 | | - "<img src=\"https://llama-stack.readthedocs.io/en/latest/_images/llama-stack.png\" alt=\"drawing\" width=\"500\"/>\n", |
| 14 | + "<img src=\"https://llamastack.github.io/latest/_images/llama-stack.png\" alt=\"drawing\" width=\"500\"/>\n", |
15 | 15 | "\n", |
16 | 16 | "[Llama Stack](https://github.com/meta-llama/llama-stack) defines and standardizes the set of core building blocks needed to bring generative AI applications to market. These building blocks are presented in the form of interoperable APIs with a broad set of Service Providers providing their implementations.\n", |
17 | 17 | "\n", |
18 | | - "Read more about the project here: https://llama-stack.readthedocs.io/en/latest/index.html\n", |
| 18 | + "Read more about the project here: https://llamastack.github.io/latest/getting_started/index.html\n", |
19 | 19 | "\n", |
20 | 20 | "In this guide, we will showcase how you can build LLM-powered agentic applications using Llama Stack.\n", |
21 | 21 | "\n", |
|
75 | 75 | }, |
76 | 76 | { |
77 | 77 | "cell_type": "code", |
78 | | - "execution_count": 1, |
| 78 | + "execution_count": null, |
79 | 79 | "id": "J2kGed0R5PSf", |
80 | 80 | "metadata": { |
81 | 81 | "colab": { |
|
113 | 113 | } |
114 | 114 | ], |
115 | 115 | "source": [ |
116 | | - "import os \n", |
| 116 | + "import os\n", |
117 | 117 | "import subprocess\n", |
118 | 118 | "import time\n", |
119 | 119 | "\n", |
120 | | - "!pip install uv \n", |
| 120 | + "!pip install uv\n", |
121 | 121 | "\n", |
122 | 122 | "if \"UV_SYSTEM_PYTHON\" in os.environ:\n", |
123 | 123 | " del os.environ[\"UV_SYSTEM_PYTHON\"]\n", |
124 | 124 | "\n", |
125 | 125 | "# this command installs all the dependencies needed for the llama stack server with the together inference provider\n", |
126 | | - "!uv run --with llama-stack llama stack build --distro together --image-type venv \n", |
| 126 | + "!uv run --with llama-stack llama stack build --distro together --image-type venv\n", |
127 | 127 | "\n", |
128 | 128 | "def run_llama_stack_server_background():\n", |
129 | 129 | " log_file = open(\"llama_stack_server.log\", \"w\")\n", |
|
134 | 134 | " stderr=log_file,\n", |
135 | 135 | " text=True\n", |
136 | 136 | " )\n", |
137 | | - " \n", |
| 137 | + "\n", |
138 | 138 | " print(f\"Starting Llama Stack server with PID: {process.pid}\")\n", |
139 | 139 | " return process\n", |
140 | 140 | "\n", |
141 | 141 | "def wait_for_server_to_start():\n", |
142 | 142 | " import requests\n", |
143 | 143 | " from requests.exceptions import ConnectionError\n", |
144 | 144 | " import time\n", |
145 | | - " \n", |
| 145 | + "\n", |
146 | 146 | " url = \"http://0.0.0.0:8321/v1/health\"\n", |
147 | 147 | " max_retries = 30\n", |
148 | 148 | " retry_interval = 1\n", |
149 | | - " \n", |
| 149 | + "\n", |
150 | 150 | " print(\"Waiting for server to start\", end=\"\")\n", |
151 | 151 | " for _ in range(max_retries):\n", |
152 | 152 | " try:\n", |
|
157 | 157 | " except ConnectionError:\n", |
158 | 158 | " print(\".\", end=\"\", flush=True)\n", |
159 | 159 | " time.sleep(retry_interval)\n", |
160 | | - " \n", |
| 160 | + "\n", |
161 | 161 | " print(\"\\nServer failed to start after\", max_retries * retry_interval, \"seconds\")\n", |
162 | 162 | " return False\n", |
163 | 163 | "\n", |
164 | 164 | "\n", |
165 | | - "# use this helper if needed to kill the server \n", |
| 165 | + "# use this helper if needed to kill the server\n", |
166 | 166 | "def kill_llama_stack_server():\n", |
167 | 167 | " # Kill any existing llama stack server processes\n", |
168 | 168 | " os.system(\"ps aux | grep -v grep | grep llama_stack.core.server.server | awk '{print $2}' | xargs kill -9\")\n" |
|
242 | 242 | }, |
243 | 243 | { |
244 | 244 | "cell_type": "code", |
245 | | - "execution_count": 4, |
| 245 | + "execution_count": null, |
246 | 246 | "id": "E1UFuJC570Tk", |
247 | 247 | "metadata": { |
248 | 248 | "colab": { |
|
407 | 407 | "from llama_stack_client import LlamaStackClient\n", |
408 | 408 | "\n", |
409 | 409 | "client = LlamaStackClient(\n", |
410 | | - " base_url=\"http://0.0.0.0:8321\", \n", |
| 410 | + " base_url=\"http://0.0.0.0:8321\",\n", |
411 | 411 | " provider_data = {\n", |
412 | | - " \"tavily_search_api_key\": os.environ['TAVILY_SEARCH_API_KEY'], \n", |
| 412 | + " \"tavily_search_api_key\": os.environ['TAVILY_SEARCH_API_KEY'],\n", |
413 | 413 | " \"together_api_key\": os.environ['TOGETHER_API_KEY']\n", |
414 | 414 | " }\n", |
415 | 415 | ")" |
|
1177 | 1177 | }, |
1178 | 1178 | { |
1179 | 1179 | "cell_type": "code", |
1180 | | - "execution_count": 13, |
| 1180 | + "execution_count": null, |
1181 | 1181 | "id": "WS8Gu5b0APHs", |
1182 | 1182 | "metadata": { |
1183 | 1183 | "colab": { |
|
1207 | 1207 | "from termcolor import cprint\n", |
1208 | 1208 | "\n", |
1209 | 1209 | "agent = Agent(\n", |
1210 | | - " client, \n", |
| 1210 | + " client,\n", |
1211 | 1211 | " model=\"meta-llama/Llama-3.3-70B-Instruct\",\n", |
1212 | 1212 | " instructions=\"You are a helpful assistant. Use websearch tool to help answer questions.\",\n", |
1213 | 1213 | " tools=[\"builtin::websearch\"],\n", |
|
1249 | 1249 | }, |
1250 | 1250 | { |
1251 | 1251 | "cell_type": "code", |
1252 | | - "execution_count": 14, |
| 1252 | + "execution_count": null, |
1253 | 1253 | "id": "GvLWltzZCNkg", |
1254 | 1254 | "metadata": { |
1255 | 1255 | "colab": { |
|
1367 | 1367 | " chunk_size_in_tokens=512,\n", |
1368 | 1368 | ")\n", |
1369 | 1369 | "rag_agent = Agent(\n", |
1370 | | - " client, \n", |
| 1370 | + " client,\n", |
1371 | 1371 | " model=model_id,\n", |
1372 | 1372 | " instructions=\"You are a helpful assistant\",\n", |
1373 | 1373 | " tools = [\n", |
|
2154 | 2154 | }, |
2155 | 2155 | { |
2156 | 2156 | "cell_type": "code", |
2157 | | - "execution_count": 21, |
| 2157 | + "execution_count": null, |
2158 | 2158 | "id": "vttLbj_YO01f", |
2159 | 2159 | "metadata": { |
2160 | 2160 | "colab": { |
|
2217 | 2217 | "from termcolor import cprint\n", |
2218 | 2218 | "\n", |
2219 | 2219 | "agent = Agent(\n", |
2220 | | - " client, \n", |
| 2220 | + " client,\n", |
2221 | 2221 | " model=model_id,\n", |
2222 | 2222 | " instructions=\"You are a helpful assistant\",\n", |
2223 | 2223 | " tools=[\"mcp::filesystem\"],\n", |
|
2283 | 2283 | }, |
2284 | 2284 | { |
2285 | 2285 | "cell_type": "code", |
2286 | | - "execution_count": 22, |
| 2286 | + "execution_count": null, |
2287 | 2287 | "id": "4iCO59kP20Zs", |
2288 | 2288 | "metadata": { |
2289 | 2289 | "colab": { |
|
2317 | 2317 | "from llama_stack_client import Agent, AgentEventLogger\n", |
2318 | 2318 | "\n", |
2319 | 2319 | "agent = Agent(\n", |
2320 | | - " client, \n", |
| 2320 | + " client,\n", |
2321 | 2321 | " model=\"meta-llama/Llama-3.3-70B-Instruct\",\n", |
2322 | 2322 | " instructions=\"You are a helpful assistant. Use web_search tool to answer the questions.\",\n", |
2323 | 2323 | " tools=[\"builtin::websearch\"],\n", |
|
2846 | 2846 | }, |
2847 | 2847 | { |
2848 | 2848 | "cell_type": "code", |
2849 | | - "execution_count": 29, |
| 2849 | + "execution_count": null, |
2850 | 2850 | "id": "44e05e16", |
2851 | 2851 | "metadata": {}, |
2852 | 2852 | "outputs": [ |
|
2880 | 2880 | "!curl -O https://raw.githubusercontent.com/meta-llama/llama-models/refs/heads/main/Llama_Repo.jpeg\n", |
2881 | 2881 | "\n", |
2882 | 2882 | "from IPython.display import Image\n", |
2883 | | - "Image(\"Llama_Repo.jpeg\", width=256, height=256)\n", |
2884 | | - "\n" |
| 2883 | + "Image(\"Llama_Repo.jpeg\", width=256, height=256)\n" |
2885 | 2884 | ] |
2886 | 2885 | }, |
2887 | 2886 | { |
|
0 commit comments