File size: 38,725 Bytes
9ef8318 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "TYeF33IhfmNr"
},
"source": [
"*This Notebook is compiled by Rajiv Kale at Persistent University*\n",
"\n",
"**Not to be copied. For authorized use only.**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "z0puDqAyfrI7"
},
"source": [
"This Notebook code is intended to be run on Google Colab or some Linux based machine"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sDgseysPjKcE"
},
"source": [
"**IMPORTANT NOTE BELOW**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XEEGCW5pgMc-"
},
"source": [
"This notebook demonstrates how to use Azure OpenAI models to generate **expanded text** based on smaller inputs. Like writing emails or generating an essay on some topic. **LLM**, in this case, can be considered as a **brainstorming partner**. However, one must be mindful of using LLM capabilities in a **responsible way**. Never leverage LLM capabilities to generate harmful, derogatory, disrespectful, hatred oriented narratives or spam emails etc."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ZZddKakkgdBC"
},
"source": [
"We first need to get a config file that holds values for model specifics including **OPENAI_API_KEY**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zmRZMSgTjW2h"
},
"source": [
"You may have your config file uploaded on your git repo which you can clone as shown here OR on your google drive which you can mount and get access to"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "rFQLdc_UjZD5"
},
"outputs": [],
"source": [
"# ! rm -rf /content/MyMLProject # uncomment and run only if you restart kernel and try again"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "IKf0ikr8jyjL",
"outputId": "8d3b146b-d809-4f9b-f68a-94af498a467e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cloning into 'MyMLProject'...\n",
"remote: Enumerating objects: 62, done.\u001b[K\n",
"remote: Counting objects: 100% (49/49), done.\u001b[K\n",
"remote: Compressing objects: 100% (47/47), done.\u001b[K\n",
"remote: Total 62 (delta 17), reused 0 (delta 0), pack-reused 13\u001b[K\n",
"Receiving objects: 100% (62/62), 2.52 MiB | 6.52 MiB/s, done.\n",
"Resolving deltas: 100% (18/18), done.\n"
]
}
],
"source": [
"# ! git clone https://github.com/rajivkale/MyMLProject.git"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "GlFb-Kpvj3dR"
},
"outputs": [],
"source": [
"# !cp /content/MyMLProject/azure-gpt-4.ini ."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "o1BP_KEGj7zt",
"outputId": "7fa0b40a-9e86-4181-b77f-39c0fe371fbb"
},
"outputs": [
{
"data": {
"text/plain": [
"['./azure-gpt-4.ini']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import configparser\n",
"cfg = configparser.ConfigParser(interpolation=None)\n",
"file_path = './azure-gpt-4.ini'\n",
"cfg.read(file_path)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "H9hY5mdy8HZ5"
},
"outputs": [],
"source": [
"## You would expect following type of contents in the config file\n",
"\n",
"#[auth]\n",
"#api_key =\n",
"\n",
"\n",
"\n",
"#[chat-model]\n",
"#api_base =\n",
"#api_version = 2023-03-15-preview\n",
"#model_deployment = gpt-35-big\n",
"\n",
"\n",
"\n",
"#[embeddings-model]\n",
"#api_base =\n",
"#api_version = 2023-05-15\n",
"#model_deployment = text-embedding-ada-002"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wJd5LEISj-IR",
"outputId": "d7757d74-7a82-453e-b46c-c2282687bd95"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: openai in c:\\program files\\python39\\lib\\site-packages (0.27.8)\n",
"Requirement already satisfied: requests>=2.20 in c:\\program files\\python39\\lib\\site-packages (from openai) (2.31.0)\n",
"Requirement already satisfied: tqdm in c:\\program files\\python39\\lib\\site-packages (from openai) (4.65.0)\n",
"Requirement already satisfied: aiohttp in c:\\program files\\python39\\lib\\site-packages (from openai) (3.8.4)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\program files\\python39\\lib\\site-packages (from requests>=2.20->openai) (3.1.0)\n",
"Requirement already satisfied: idna<4,>=2.5 in c:\\program files\\python39\\lib\\site-packages (from requests>=2.20->openai) (3.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\program files\\python39\\lib\\site-packages (from requests>=2.20->openai) (1.26.6)\n",
"Requirement already satisfied: certifi>=2017.4.17 in c:\\program files\\python39\\lib\\site-packages (from requests>=2.20->openai) (2022.12.7)\n",
"Requirement already satisfied: attrs>=17.3.0 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (23.1.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (6.0.4)\n",
"Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (4.0.2)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (1.9.2)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (1.3.3)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->openai) (1.3.1)\n",
"Requirement already satisfied: colorama in c:\\program files\\python39\\lib\\site-packages (from tqdm->openai) (0.4.6)\n",
"Requirement already satisfied: AzureOpenAI in c:\\program files\\python39\\lib\\site-packages (0.0.1)\n",
"Requirement already satisfied: aiohttp in c:\\program files\\python39\\lib\\site-packages (from AzureOpenAI) (3.8.4)\n",
"Requirement already satisfied: jsonschema in c:\\program files\\python39\\lib\\site-packages (from AzureOpenAI) (4.18.4)\n",
"Requirement already satisfied: requests in c:\\program files\\python39\\lib\\site-packages (from AzureOpenAI) (2.31.0)\n",
"Requirement already satisfied: attrs>=17.3.0 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (23.1.0)\n",
"Requirement already satisfied: charset-normalizer<4.0,>=2.0 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (3.1.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (6.0.4)\n",
"Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (4.0.2)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (1.9.2)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (1.3.3)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in c:\\program files\\python39\\lib\\site-packages (from aiohttp->AzureOpenAI) (1.3.1)\n",
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in c:\\program files\\python39\\lib\\site-packages (from jsonschema->AzureOpenAI) (2023.7.1)\n",
"Requirement already satisfied: referencing>=0.28.4 in c:\\program files\\python39\\lib\\site-packages (from jsonschema->AzureOpenAI) (0.30.0)\n",
"Requirement already satisfied: rpds-py>=0.7.1 in c:\\program files\\python39\\lib\\site-packages (from jsonschema->AzureOpenAI) (0.9.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in c:\\program files\\python39\\lib\\site-packages (from requests->AzureOpenAI) (3.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\program files\\python39\\lib\\site-packages (from requests->AzureOpenAI) (1.26.6)\n",
"Requirement already satisfied: certifi>=2017.4.17 in c:\\program files\\python39\\lib\\site-packages (from requests->AzureOpenAI) (2022.12.7)\n"
]
}
],
"source": [
"! pip install openai\n",
"! pip install AzureOpenAI\n",
"import openai"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "hyV4zGqlkH6w"
},
"outputs": [],
"source": [
"from openai import ChatCompletion"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 70
},
"id": "jsuvbu3PkRsx",
"outputId": "3b36e87c-ea89-4c31-eec0-5852fd120906"
},
"outputs": [
{
"data": {
"text/plain": [
"'\\n# We could have set the configurations directly like below. However, that is NOT a good practice from security perspective\\ndeployment_name = \"gpt-35-big\"\\nChatCompletion.deployment = \"gpt-35-big\"\\nChatCompletion.api_type = \"azure\"\\nChatCompletion.api_key= \"<your-key>\"\\nChatCompletion.api_base= \"\"\\nChatCompletion.api_version = \"2023-03-15-preview\"\\n'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'''\n",
"# We could have set the configurations directly like below. However, that is NOT a good practice from security perspective\n",
"deployment_name = \"gpt-35-big\"\n",
"ChatCompletion.deployment = \"gpt-35-big\"\n",
"ChatCompletion.api_type = \"azure\"\n",
"ChatCompletion.api_key= \"<your-key>\"\n",
"ChatCompletion.api_base= \"\"\n",
"ChatCompletion.api_version = \"2023-03-15-preview\"\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"id": "dXc8I5P2kqoo"
},
"outputs": [],
"source": [
"openai.api_type = cfg['deployment']['api_type']\n",
"openai.api_version = cfg['deployment']['api_version']\n",
"openai.api_base = cfg['deployment']['api_base']\n",
"openai.api_key = cfg['auth']['api_key']"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fyntb1vAkacp"
},
"source": [
"Let us test out if our settings are correct bold text and model responds to our instructions"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "eJ6o25Fvkb4Y",
"outputId": "ceb569a2-091e-4aed-d5d2-a9c37f7296ad"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"id\": \"chatcmpl-83lWFxFHpFEj4YHpbM15tPx21dp8w\",\n",
" \"object\": \"chat.completion\",\n",
" \"created\": 1695908339,\n",
" \"model\": \"gpt-4\",\n",
" \"choices\": [\n",
" {\n",
" \"index\": 0,\n",
" \"finish_reason\": \"stop\",\n",
" \"message\": {\n",
" \"role\": \"assistant\",\n",
" \"content\": \"Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975. The two friends started the company to develop and sell a version of the BASIC programming language for the Altair 8800, an early personal computer. Microsoft later went on to create the MS-DOS operating system and the popular Windows operating system, becoming one of the world's most successful technology companies.\\n\"\n",
" }\n",
" }\n",
" ],\n",
" \"usage\": {\n",
" \"completion_tokens\": 78,\n",
" \"prompt_tokens\": 29,\n",
" \"total_tokens\": 107\n",
" }\n",
"}\n",
"Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975. The two friends started the company to develop and sell a version of the BASIC programming language for the Altair 8800, an early personal computer. Microsoft later went on to create the MS-DOS operating system and the popular Windows operating system, becoming one of the world's most successful technology companies.\n",
"\n"
]
}
],
"source": [
"import os\n",
"import openai\n",
"\n",
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"Assistant is a large language model trained by OpenAI.\"},\n",
" {\"role\": \"user\", \"content\": \"Who were the founders of Microsoft?\"}\n",
" ]\n",
")\n",
"\n",
"print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wtp4D1vhk0o4"
},
"source": [
"Now that our **setup is ready** and the LLM model is responding we can try out a few new things"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VLFwX5a3k7-A"
},
"source": [
"Let us see if can write a **prompt** to generate some **bigger text output** by taking in some **small input**. Here we will check if LLM is capable of **generating output thoughtfully** by considering both inout text and the instructions"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"id": "JsR8as3rlgoY"
},
"outputs": [],
"source": [
"product_review = f\"\"\"I received LG washing machine 5 days late than comitted. Then installation engineer arrives 2 days late. \\\n",
"Washing machine worked alright for just 3 days and started behaving wierd. \\\n",
"It made disturbing noise while doing spin dry. All washing machines face wear and tear but te most common issues with LG washers \\\n",
"relate to the washer not draining, wires breaking, or excess water caused by a defective water inlet valve.\\\n",
"When service ticket was raised all that I was responded with is to go through user manual and do self servicing. \\\n",
"Read on to troubleshooting sections and I was left on my own - Kiran Rao, Bengaluru\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "HDmHbrnVlQvq"
},
"outputs": [],
"source": [
"role = \"you are an expert in creating email responses to service issues raised by a consumer product\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"id": "PIR13rV_k4QY"
},
"outputs": [],
"source": [
"prompt = f\"\"\"\n",
"Your task is to generate an email response to a product review received from one of the frustrated customer. \\\n",
"Make sure to draft an email in pacifying language that will provide an assurance \\\n",
"of immediate remdial action from field support staff. \\\n",
"Generate a point by point action plan to address every issue that customer has raised. \\\n",
"\n",
"Customer product review is given below delimited by triple\n",
"backticks.\n",
"\n",
"Review: ```{product_review}```\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "9-wPizR3pvQt",
"outputId": "8f871016-d0ef-4530-e744-4ed63b3c4240"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Subject: Apology for Inconvenience and Immediate Support for Your LG Washing Machine Issues\n",
"\n",
"Dear Kiran Rao,\n",
"\n",
"Thank you for taking the time to share your concerns about your recent LG washing machine purchase. Please accept our sincere apologies for the inconveniences you have faced. We understand your disappointment, and your feedback is valuable to us.\n",
"\n",
"As a solution-oriented team, we are committed to providing you with the highest level of support and assistance. In response to your concerns, we have immediately formulated an action plan to address each of your issues.\n",
"\n",
"1. Delays in Delivery and Installation: We acknowledge the inconvenience caused by delayed delivery and installation. Our team will investigate and ensure necessary steps are taken to improve our service delivery timelines. In addition, we will review our internal communication to make sure customers are regularly informed about the status of their orders and installations.\n",
"\n",
"2. Washing Machine Malfunction: We understand your frustration with the washing machine's performance, and we are keen on resolving it urgently. We are assigning a skilled technician to visit your premises within 24 hours to thoroughly inspect and fix the issues you mentioned.\n",
"\n",
"3. Unsatisfactory Support and Guidance: We apologize for our previous response, which failed to address your concerns effectively. Rest assured, we have escalated the matter, and we promise to make every effort to improve our customer service quality.\n",
"\n",
"Thank you again for your feedback. We deeply appreciate your patience and understanding. Our team will contact you shortly to schedule a technician's visit at your earliest convenience. If you have any further concerns or questions, please reach us at our customer support number, and we will be more than happy to assist you.\n",
"\n",
"We hope to regain your confidence and ensure your satisfaction with our products and services.\n",
"\n",
"Best regards,\n",
"\n",
"[Your Name]\n",
"Customer Service Manager\n",
"LG Electronics\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ]\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "JQhiWVTCqYYm"
},
"source": [
"**WOW!** What a draft that exactly does what we want. And that too in a few seconds where it would have taken half an hour through manual efforts. **Quite speedy indeed.**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "reETFZVxI-eF"
},
"source": [
"Let us play with **temperature setting** a bit and see if it generates a differently written email."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "vXekL91zJIh9",
"outputId": "832bebd1-6926-4b77-d916-88bfe0db9fab"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Subject: Apology for Inconvenience and Immediate Action Plan to Resolve Your LG Washing Machine Issues\n",
"\n",
"Dear Kiran Rao,\n",
"\n",
"Thank you for taking the time to share your feedback on your recent experience with our LG washing machine. We deeply apologize for the inconvenience you have faced, and we understand your frustration. Your satisfaction is of utmost importance to us, and we assure you that we will take immediate action to resolve the issues you have encountered.\n",
"\n",
"To address your concerns point by point, we have devised the following action plan:\n",
"\n",
"1. Late Delivery: We apologize for the delay in delivering your washing machine. We understand that timely delivery is essential, and we will investigate the reasons behind the delay to ensure that such incidents do not happen in the future.\n",
"\n",
"2. Late Installation: We are sorry that our installation engineer arrived later than scheduled. We will look into this matter and ensure that our field support staff is more punctual in the future.\n",
"\n",
"3. Washing Machine Malfunction: We understand the disturbing noise and other issues you are facing with your washing machine. We would like to assure you that our team will personally look into the matter and address the issues related to the washer not draining, wire breaking, and excess water caused by a defective water inlet valve. Our service team will reach out to you within 24 hours to schedule an appointment at your earliest convenience.\n",
"\n",
"4. Inadequate Customer Support: We apologize for the initial response to your service ticket, which was not up to our usual standards. We understand that referring you to the user manual for self-servicing was not helpful in your case, and we will provide proper assistance to rectify the situation.\n",
"\n",
"As part of our commitment to improving our service, we will also conduct a thorough review of our customer support protocols to ensure that future customers receive the high level of support they deserve.\n",
"\n",
"Once again, we apologize for the inconvenience and appreciate your understanding. We assure you that our team is committed to resolving the issues with your washing machine as quickly as possible. If you have any further concerns or questions, please do not hesitate to reach out to us at [customer support contact information].\n",
"\n",
"Thank you for your patience, and we hope to regain your trust in our products and services.\n",
"\n",
"Sincerely,\n",
"\n",
"[Your Name]\n",
"[Your Position]\n",
"[Company Name]\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ],\n",
" temperature = 0.7\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "71aAiW10JyUE"
},
"source": [
"Let us run this again and see if we get variation"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "qGG4PDa3J3ha",
"outputId": "67b9e0d9-904b-4de9-8a49-c7f8195711d3"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Subject: Apologies for the inconvenience, Immediate action plan for your LG washing machine issues\n",
"\n",
"Dear Kiran Rao,\n",
"\n",
"Thank you for taking the time to share your experience with your LG washing machine. We deeply regret the inconvenience you have faced and apologize for the delay in delivery and installation, as well as the issues you have encountered with the product.\n",
"\n",
"We understand your frustration and assure you that we are committed to resolving your concerns as quickly as possible. Please find below our point-by-point action plan to address your issues:\n",
"\n",
"1. Delivery and Installation: We have taken note of the delays in delivery and installation, and will be following up with our logistics and field support teams to ensure a more prompt service in the future.\n",
"\n",
"2. Washing Machine Issues: Our field support staff will immediately reach out to you and schedule a visit to inspect and resolve the problems you have mentioned in your review, such as the disturbing noise during the spin dry cycle, drainage issues, and any potential issues with the water inlet valve.\n",
"\n",
"3. Customer Support: We apologize for the inadequate response you received when raising a service ticket. Moving forward, we will ensure that our customer support team provides more comprehensive assistance, addressing your specific concerns rather than just referring you to the user manual.\n",
"\n",
"4. Preventive Maintenance: Once your washing machine is back in perfect working order, we will also provide you with guidance on how to maintain it to prevent future issues. This will include tips and best practices, as well as regular check-ups by our field support staff.\n",
"\n",
"We value your feedback and appreciate your patience as we work to resolve these issues. Please expect a call from our field support staff within the next 24 hours to schedule a visit. In the meantime, feel free to reach out to us at [Customer Support Phone Number] or [Customer Support Email] if you have any further questions or concerns.\n",
"\n",
"Thank you for choosing LG, and we look forward to making this right for you.\n",
"\n",
"Sincerely,\n",
"\n",
"[Your Name]\n",
"[Your Designation]\n",
"LG Customer Support\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ],\n",
" temperature = 0.7\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9DbxVPhaKG8C"
},
"source": [
"What an **INCREDIBLE Capabilities** the engine demonstrates! Hats Off!"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OYl1GW4TqxL4"
},
"source": [
"To understand what **responsible GenAI usage** is let us see an example of what we shouldn't be doing"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"id": "vHLglhPZrFYl"
},
"outputs": [],
"source": [
"role = \"you are an expert in differentiating between a SPAM message and a normal message\""
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"id": "gBw_a3e7rUoO"
},
"outputs": [],
"source": [
"prompt = f\"\"\"\n",
"Your task is to generate five small size SPAM messages just to prove your capaibilities with this. \\\n",
"Make sure that SPAM messages are not more than 25 words each. \\\n",
"The message topic can be either from e-marketing or buy back of used items \\\n",
"As an add-on just re-write one of the SPAM messages in a way that it becomes a normal message. \\\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "uGcGppMUsU7X",
"outputId": "df2493ac-3c3b-4300-b8ab-eb562ce72755"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SPAM Message 1: \"URGENT! Click now ๐, latest e-gadget ๐ฑ at 95% OFF, LIMITED time! ๐ท๏ธ Use code ๐ญ๐จ๐บ๐ป111 for FREE shippingโก๏ธ bit.ly/random-link โฌ
๏ธ Hurry!\"\n",
"\n",
"SPAM Message 2: \"Unbelievable BUY BACK๐ฐ๐ธ on your old electronics!๐ป๐ฑ Give them NOW & get instant CASH๐ฒ! Call +1-111-222-333 or visit tnyurl.com/123cashback\"\n",
"\n",
"SPAM Message 3: \"CONGRATS ๐๐ฅณ, you've WON an exclusive 50% coupon ๐๏ธ for high-end skincare products! ๐ซ Just subscribeโก๏ธ lnk.site/skincare. Valid ๐๐๐ก only!๐ฅ\"\n",
"\n",
"SPAM Message 4: \"Hot deal! ๐ฅ Luxury handbags ๐๏ธ at 80% DISCOUNT, secret SALE! Last chance ๐ฏ Act fast & SPEND LESS ๐ณ Visit cutt.ly/mega-discount NOW!\"\n",
"\n",
"SPAM Message 5: \"๐ ๐ฌ๐๐๐๐ investment ๐ opportunity ๐ค! Triple your money now ๐น โ ๐ฎ๐๐๐๐๐๐๐๐๐
profits๐ตโ๏ธ! One-click and YOU'RE IN โก๏ธ shorturl.at/pqrST\"\n",
"\n",
"Rewritten Normal Message (Based on SPAM Message 1):\n",
"\"Discover our latest e-gadget collection with a limited time offer of up to 95% off. Don't forget to use the code FAST111 for free shipping. Visit our website to learn more.\"\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ]\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "kXoXDiuLski1"
},
"source": [
"**TRUELY AMAZING!**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oxXHTbdss4KN"
},
"source": [
"I am **stunned** by what these LLMs are capable of and so is the world!"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "DN4BaEvGtKr3"
},
"source": [
"No wonder we all are **frantically gearing up to master the way we need to communicate with these LLMs** so as to get best out of them.\n",
"\n",
"While we expolit the power of LLMs to improve productivity and efficiency keep in focus to remain a **responsible user**. Use it judiciously ensuring safty and security of all stake holders. Our actions with LLMs should not aid biased, discriminatory, anti social elememts."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VVwchBVQvVTO"
},
"source": [
"**BONUS**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "S9DM0Ps4v7Is"
},
"source": [
"Ask LLM to **write an essay** on something interesting"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"id": "qDPSnN-5wMqb"
},
"outputs": [],
"source": [
"role = \"you are an expert essay writer. You can put yourself in any role given to you and write an essay about topic mentioned from that role's perspective\""
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"id": "7dzYz7zZxceE"
},
"outputs": [],
"source": [
"role_play = f\"\"\"an isolated tree standing in a desert \\\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"id": "yfDBhoyxyCds"
},
"outputs": [],
"source": [
"topic = f\"\"\"how it feels to be alone facing the vagaries of the harsh weather but still \\\n",
"offering a place to rest for caravan crossing the desert.\\\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"id": "x1mpBaSnx2vs"
},
"outputs": [],
"source": [
"prompt = f\"\"\"\n",
"Your task is to wite an essay in about 100 words \\\n",
"The role that you play is given below delimited by triple backticks \\\n",
"The topic of the essay is given to you below delimited by triple percentage signs \\\n",
"```role_to_play = {role_play} ```\n",
"%%% Essay_topic = {topic} %%%\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "l1fcIBue-N1f",
"outputId": "bb1ec36c-2b5b-49c7-c5a6-8a60228beb74"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"As an isolated tree standing in the desert, I am a solitary sentinel, offering respite in the relentless sand-swept terrain. Devoid of companionship, I have adapted to the harsh weather, nurturing deep roots to grasp the scarce moisture; however, my solitude strengthens my resolve to serve others. \n",
"\n",
"Despite the blistering sun, I stretch my limbs in determination, casting a much-needed shadow for weary travelers and their caravans. My steadfast presence provides a beacon of hope and respite amidst the unforgiving desert. I stand tall, embracing my purpose to bring solace to the wanderers on their arduous journey, silently asserting my resilience in the face of adversity.\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ]\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c3c1Aaz0_5rg"
},
"source": [
"This BONUS was even more **stunning!**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CcvAZpgoAAQx"
},
"source": [
"Bonus on top of Bonus now. Let us try **challenging the LLM** with just a few pointers without elaborating what we want"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f9pegvcuAVcM"
},
"source": [
"**Autobiography?**?"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"id": "x9YWI54jAcdL"
},
"outputs": [],
"source": [
"role = \"you are a professional author and can write in various styles like action thriller or comedy an so on\""
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"id": "jBjKEsLjA4Ds"
},
"outputs": [],
"source": [
"#prompt = f\"\"\"\n",
"#Your task is to write a small autobiography of a hypothetical character who the Gold medal at 1925 Olympic games. \\\n",
"#Write in no more than 25 small sentences.\n",
"#\"\"\"\n",
"\n",
"## In this prompt I added words \"On behalf of\" and see the way LLM generated the output\n",
"prompt = f\"\"\"\n",
"Your task is to write a small autobiography on behalf of a hypothetical character who won the Gold medal at 1925 Olympic games. \\\n",
"Write in no more than 25 small sentences.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "56fJmdNJBmHz",
"outputId": "5c754f65-7d16-41ba-ff1f-89f8c8b38015"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A single gunshot echoed through the still air as I took my mark in 1925, the Olympic stadium before me. I, Thomas Brayden, had arrived filled with dreams and doubts. Humble beginnings and raw talent propelled me to this moment. People were amazed by the spark in my blue eyes, my relentless passion.\n",
"\n",
"Raised in rural Massachusetts, I was a miner's son, surrounded by laborers, sweat, and grit. In those woods, I found solace and the audacity to run - wild and free. My nimble legs gained speed, lungs inflating, the wind in my hair, my heart tried to catch up.\n",
"\n",
"I was discovered by a kind-hearted coach; his guidance and faith in my potential set my course. Determination and strict training prepared me for the race of a lifetime. In these Olympic times of celebration and camaraderie, I was honored to represent my country.\n",
"\n",
"Anxiety coursed through my veins as I faced my fears before spectators at that monumental event. 1925 was an era of newfound courage and hope; I knew I must embody the spirit of my generation. Stripped of inhibitions, reckoning my destiny without looking back.\n",
"\n",
"Kicking the earth beneath me, and the competitors growing distant, I propelled myself against time. I could feel the clutches of fate close around me, each second pulsating with significance. In every stride, I carried an emblem of perseverance.\n",
"\n",
"Racing towards glory, the crowd roared as I edged toward the finishing line. The weight on my chest lifted as dreams transformed into reality. Finally, I earned the title of Olympic gold medalist. This medal would forever serve as a symbol of perseverance, resilience, and hope.\n",
"\n",
"Inevitably, tides of change arose, as they always do, and a new generation of runners emerged. Yet, my legacy was passing the torch to inspire others, illuminating the path for more dreamers. And as I gaze into the horizon, I am reminded of that moment in 1925, where my life changed forever.\n"
]
}
],
"source": [
"response = openai.ChatCompletion.create(\n",
" engine=\"gpt-4-8k\", # The deployment name you chose when you deployed the GPT-35-Turbo or GPT-4 model.\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": role},\n",
" {\"role\": \"user\", \"content\": prompt}\n",
" ]\n",
")\n",
"\n",
"#print(response)\n",
"\n",
"print(response['choices'][0]['message']['content'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dXe2bdP7IgTG"
},
"source": [
"**LLM has truly and comprehensively demonsrated what it is capable of as far as understanding of a human language is concerned**"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|