|
299 | 299 | },
|
300 | 300 | {
|
301 | 301 | "cell_type": "code",
|
302 |
| - "execution_count": 2, |
| 302 | + "execution_count": 12, |
303 | 303 | "metadata": {},
|
304 | 304 | "outputs": [],
|
305 | 305 | "source": [
|
|
312 | 312 | "source": [
|
313 | 313 | "#### Now we can learn about the various prompt formats available \n",
|
314 | 314 | "\n",
|
315 |
| - "When you run the cell below-you will see all the options for different template" |
| 315 | + "When you run the cell below-you will see models available and then we can check details for model specific prompts" |
316 | 316 | ]
|
317 | 317 | },
|
318 | 318 | {
|
319 | 319 | "cell_type": "code",
|
320 |
| - "execution_count": 90, |
| 320 | + "execution_count": 20, |
321 | 321 | "metadata": {},
|
322 | 322 | "outputs": [
|
323 | 323 | {
|
324 | 324 | "name": "stdout",
|
325 | 325 | "output_type": "stream",
|
326 | 326 | "text": [
|
327 |
| - "+-----------+---------------------------------+\n", |
328 |
| - "\u001b[1m\u001b[97m| Role | Template Name |\u001b[0m\n", |
329 |
| - "+-----------+---------------------------------+\n", |
330 |
| - "| user | user-default |\n", |
331 |
| - "| assistant | assistant-builtin-tool-call |\n", |
332 |
| - "| assistant | assistant-custom-tool-call |\n", |
333 |
| - "| assistant | assistant-default |\n", |
334 |
| - "| system | system-builtin-and-custom-tools |\n", |
335 |
| - "| system | system-builtin-tools-only |\n", |
336 |
| - "| system | system-custom-tools-only |\n", |
337 |
| - "| system | system-default |\n", |
338 |
| - "| tool | tool-success |\n", |
339 |
| - "| tool | tool-failure |\n", |
340 |
| - "+-----------+---------------------------------+\n" |
| 327 | + "Traceback (most recent call last):\n", |
| 328 | + " File \"/opt/miniconda3/bin/llama\", line 8, in <module>\n", |
| 329 | + " sys.exit(main())\n", |
| 330 | + " ^^^^^^\n", |
| 331 | + " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/llama.py\", line 44, in main\n", |
| 332 | + " parser.run(args)\n", |
| 333 | + " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/llama.py\", line 38, in run\n", |
| 334 | + " args.func(args)\n", |
| 335 | + " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/model/prompt_format.py\", line 59, in _run_model_template_cmd\n", |
| 336 | + " raise argparse.ArgumentTypeError(\n", |
| 337 | + "argparse.ArgumentTypeError: llama3_1 is not a valid Model. Choose one from --\n", |
| 338 | + "Llama3.1-8B\n", |
| 339 | + "Llama3.1-70B\n", |
| 340 | + "Llama3.1-405B\n", |
| 341 | + "Llama3.1-8B-Instruct\n", |
| 342 | + "Llama3.1-70B-Instruct\n", |
| 343 | + "Llama3.1-405B-Instruct\n", |
| 344 | + "Llama3.2-1B\n", |
| 345 | + "Llama3.2-3B\n", |
| 346 | + "Llama3.2-1B-Instruct\n", |
| 347 | + "Llama3.2-3B-Instruct\n", |
| 348 | + "Llama3.2-11B-Vision\n", |
| 349 | + "Llama3.2-90B-Vision\n", |
| 350 | + "Llama3.2-11B-Vision-Instruct\n", |
| 351 | + "Llama3.2-90B-Vision-Instruct\n" |
341 | 352 | ]
|
342 | 353 | }
|
343 | 354 | ],
|
344 | 355 | "source": [
|
345 |
| - "!llama model template" |
346 |
| - ] |
347 |
| - }, |
348 |
| - { |
349 |
| - "cell_type": "markdown", |
350 |
| - "metadata": {}, |
351 |
| - "source": [ |
352 |
| - "## Tool Calling: Using the correct Prompt Template\n", |
353 |
| - "\n", |
354 |
| - "With `llama-cli` we can learn the correct way of defining `System_prompt` and finally get the correct behaviour from the model" |
| 356 | + "!llama model prompt-format " |
355 | 357 | ]
|
356 | 358 | },
|
357 | 359 | {
|
358 | 360 | "cell_type": "code",
|
359 |
| - "execution_count": 92, |
| 361 | + "execution_count": 21, |
360 | 362 | "metadata": {},
|
361 | 363 | "outputs": [
|
362 | 364 | {
|
363 | 365 | "name": "stdout",
|
364 | 366 | "output_type": "stream",
|
365 | 367 | "text": [
|
366 |
| - "+----------+--------------------------------------------------------------+\n", |
367 |
| - "| Name | \u001b[1m\u001b[97msystem-builtin-tools-only\u001b[0m |\n", |
368 |
| - "+----------+--------------------------------------------------------------+\n", |
369 |
| - "| Template | \u001b[1m\u001b[33m<|begin_of_text|>\u001b[0m\u001b[1m\u001b[33m<|start_header_id|>\u001b[0msystem\u001b[1m\u001b[33m<|end_header_id|>\u001b[0m↵ |\n", |
370 |
| - "| | ↵ |\n", |
371 |
| - "| | Environment: ipython↵ |\n", |
372 |
| - "| | Tools: brave_search, wolfram_alpha↵ |\n", |
373 |
| - "| | Cutting Knowledge Date: December 2023↵ |\n", |
374 |
| - "| | Today Date: 15 September 2024↵ |\n", |
375 |
| - "| | ↵ |\n", |
376 |
| - "| | You are a helpful assistant.↵ |\n", |
377 |
| - "| | \u001b[1m\u001b[33m<|eot_id|>\u001b[0m\u001b[1m\u001b[33m<|start_header_id|>\u001b[0massistant\u001b[1m\u001b[33m<|end_header_id|>\u001b[0m↵ |\n", |
378 |
| - "| | ↵ |\n", |
379 |
| - "| | |\n", |
380 |
| - "+----------+--------------------------------------------------------------+\n", |
381 |
| - "| Notes | ↵ represents newline |\n", |
382 |
| - "+----------+--------------------------------------------------------------+\n" |
| 368 | + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[m━━━━━━━━━━━━━━━━━━━┓\u001b[m\n", |
| 369 | + "┃ \u001b[1mLlama 3.1 - Prompt Formats\u001b[0m \u001b[m\u001b[1m\u001b[0m ┃\u001b[m\n", |
| 370 | + "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[m━━━━━━━━━━━━━━━━━━━┛\u001b[m\n", |
| 371 | + "\u001b[m\n", |
| 372 | + "\u001b[m\n", |
| 373 | + " \u001b[1;4mTokens\u001b[0m \u001b[m\u001b[1;4m\u001b[0m \u001b[m\n", |
| 374 | + "\u001b[m\n", |
| 375 | + "Here is a list of special tokens that are supported by Llama 3.1: \u001b[m \u001b[m\n", |
| 376 | + "\u001b[m\n", |
| 377 | + "\u001b[1;33m • \u001b[0m\u001b[1;36;40m<|begin_of_text|>\u001b[0m: Specifies the start of the prompt \u001b[m\u001b[1;33m\u001b[0m\u001b[1;36;40m\u001b[0m \u001b[m\n", |
| 378 | + "\u001b[1;33m • \u001b[0m\u001b[1;36;40m<|end_of_text|>\u001b[0m: Model will cease to generate more tokens. This token is gene\u001b[m\u001b[1;33m\u001b[0m\u001b[1;36;40m\u001b[0mrated only by the \u001b[m\n", |
| 379 | + "\u001b[1;33m \u001b[0mbase models. \u001b[m\u001b[1;33m\u001b[0m \u001b[m\n", |
| 380 | + "\u001b[1;33m • \u001b[0m\u001b[1;36;40m<|finetune_right_pad_id|>\u001b[0m: This token is used for padding text sequences to t\u001b[m\u001b[1;33m\u001b[0m\u001b[1;36;40m\u001b[0mhe same length in a \u001b[m\n", |
| 381 | + "\u001b[1;33m \u001b[0mbatch. \u001b[m:\u001b[K" |
383 | 382 | ]
|
384 | 383 | }
|
385 | 384 | ],
|
386 | 385 | "source": [
|
387 |
| - "!llama model template --name system-builtin-tools-only" |
| 386 | + "!llama model prompt-format -m Llama3.1-8B" |
388 | 387 | ]
|
389 | 388 | },
|
390 | 389 | {
|
391 | 390 | "cell_type": "markdown",
|
392 | 391 | "metadata": {},
|
393 | 392 | "source": [
|
394 |
| - "If everything is setup correctly-the model should now wrap function calls with the `|<python_tag>|` following the actualy function call. \n", |
395 |
| - "\n", |
396 |
| - "This can allow you to manage your function calling logic accordingly. \n", |
| 393 | + "## Tool Calling: Using the correct Prompt Template\n", |
397 | 394 | "\n",
|
398 |
| - "Time to test the theory" |
| 395 | + "With `llama-cli` we have already learned the right behaviour of the model" |
399 | 396 | ]
|
400 | 397 | },
|
401 | 398 | {
|
402 |
| - "cell_type": "code", |
403 |
| - "execution_count": 94, |
| 399 | + "cell_type": "markdown", |
404 | 400 | "metadata": {},
|
405 |
| - "outputs": [ |
406 |
| - { |
407 |
| - "name": "stdout", |
408 |
| - "output_type": "stream", |
409 |
| - "text": [ |
410 |
| - "+----------+----------------------------------------------------------------------------------+\n", |
411 |
| - "| Name | \u001b[1m\u001b[97massistant-builtin-tool-call\u001b[0m |\n", |
412 |
| - "+----------+----------------------------------------------------------------------------------+\n", |
413 |
| - "| Template | \u001b[1m\u001b[33m<|begin_of_text|>\u001b[0m\u001b[1m\u001b[33m<|start_header_id|>\u001b[0massistant\u001b[1m\u001b[33m<|end_header_id|>\u001b[0m↵ |\n", |
414 |
| - "| | ↵ |\n", |
415 |
| - "| | \u001b[1m\u001b[33m<|python_tag|>\u001b[0mbrave_search.call(query=\"Who won NBA in |\n", |
416 |
| - "| | 2024?\")\u001b[1m\u001b[33m<|eom_id|>\u001b[0m\u001b[1m\u001b[33m<|start_header_id|>\u001b[0massistant\u001b[1m\u001b[33m<|end_header_id|>\u001b[0m↵ |\n", |
417 |
| - "| | ↵ |\n", |
418 |
| - "| | |\n", |
419 |
| - "+----------+----------------------------------------------------------------------------------+\n", |
420 |
| - "| Notes | ↵ represents newline |\n", |
421 |
| - "| | Notice <|python_tag|> |\n", |
422 |
| - "+----------+----------------------------------------------------------------------------------+\n" |
423 |
| - ] |
424 |
| - } |
425 |
| - ], |
426 | 401 | "source": [
|
427 |
| - "!llama model template --name assistant-builtin-tool-call" |
| 402 | + "If everything is setup correctly-the model should now wrap function calls with the `|<python_tag>|` following the actualy function call. \n", |
| 403 | + "\n", |
| 404 | + "This can allow you to manage your function calling logic accordingly. \n", |
| 405 | + "\n", |
| 406 | + "Time to test the theory" |
428 | 407 | ]
|
429 | 408 | },
|
430 | 409 | {
|
|
684 | 663 | "\n",
|
685 | 664 | "[Here](https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_2#-tool-calling-(1b/3b)-) are the docs for your reference that we will be using. \n",
|
686 | 665 | "\n",
|
687 |
| - "Let's verify the details from `llama-toolchain` again and then start the prompt engineering for the small Llamas." |
688 |
| - ] |
689 |
| - }, |
690 |
| - { |
691 |
| - "cell_type": "code", |
692 |
| - "execution_count": 18, |
693 |
| - "metadata": {}, |
694 |
| - "outputs": [ |
695 |
| - { |
696 |
| - "name": "stdout", |
697 |
| - "output_type": "stream", |
698 |
| - "text": [ |
699 |
| - "Traceback (most recent call last):\n", |
700 |
| - " File \"/opt/miniconda3/bin/llama\", line 8, in <module>\n", |
701 |
| - " sys.exit(main())\n", |
702 |
| - " ^^^^^^\n", |
703 |
| - " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/llama.py\", line 44, in main\n", |
704 |
| - " parser.run(args)\n", |
705 |
| - " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/llama.py\", line 38, in run\n", |
706 |
| - " args.func(args)\n", |
707 |
| - " File \"/opt/miniconda3/lib/python3.12/site-packages/llama_toolchain/cli/model/prompt_format.py\", line 59, in _run_model_template_cmd\n", |
708 |
| - " raise argparse.ArgumentTypeError(\n", |
709 |
| - "argparse.ArgumentTypeError: llama3_1 is not a valid Model. Choose one from --\n", |
710 |
| - "Llama3.1-8B\n", |
711 |
| - "Llama3.1-70B\n", |
712 |
| - "Llama3.1-405B\n", |
713 |
| - "Llama3.1-8B-Instruct\n", |
714 |
| - "Llama3.1-70B-Instruct\n", |
715 |
| - "Llama3.1-405B-Instruct\n", |
716 |
| - "Llama3.2-1B\n", |
717 |
| - "Llama3.2-3B\n", |
718 |
| - "Llama3.2-1B-Instruct\n", |
719 |
| - "Llama3.2-3B-Instruct\n", |
720 |
| - "Llama3.2-11B-Vision\n", |
721 |
| - "Llama3.2-90B-Vision\n", |
722 |
| - "Llama3.2-11B-Vision-Instruct\n", |
723 |
| - "Llama3.2-90B-Vision-Instruct\n" |
724 |
| - ] |
725 |
| - } |
726 |
| - ], |
727 |
| - "source": [ |
728 |
| - "!llama model prompt-format" |
| 666 | + "Excercise for viewer: Use `llama-toolchain` again to verify like we did earlier and then start the prompt engineering for the small Llamas." |
729 | 667 | ]
|
730 | 668 | },
|
731 | 669 | {
|
|
903 | 841 | "cell_type": "markdown",
|
904 | 842 | "metadata": {},
|
905 | 843 | "source": [
|
906 |
| - "Hello Regex, my good old friend :) " |
| 844 | + "### Handling Tool-Calling logic for the model" |
| 845 | + ] |
| 846 | + }, |
| 847 | + { |
| 848 | + "cell_type": "markdown", |
| 849 | + "metadata": {}, |
| 850 | + "source": [ |
| 851 | + "Hello Regex, my good old friend :) \n", |
| 852 | + "\n", |
| 853 | + "With Regex, we can write a simple way to handle tool_calling and return either the model or tool call response" |
907 | 854 | ]
|
908 | 855 | },
|
909 | 856 | {
|
|
0 commit comments