Spaces:
Configuration error
Configuration error
File size: 41,830 Bytes
28e2c84 |
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 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/vanderbilt-data-science/lo-achievement/blob/main/prompt_with_context.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "S4MkldrwPA_S"
},
"source": [
"# LLMs for Self-Study\n",
"> A prompt and code template for better understanding texts\n",
"\n",
"This notebook provides a guide for using LLMs for self-study programmatically. A number of prompt templates are provided to assist with generating great assessments for self-study, and code is additionally provided for fast usage. This notebook is best leveraged for a set of documents (text or PDF preferred) **to be uploaded** for interaction with the model.\n",
"\n",
"This version of the notebook is best suited for those who prefer to use files from their local drive as context rather than copy and pasting directly into the notebook to be used as context for the model. If you prefer to copy and paste text, you should direct yourself to the [prompt_with_context](https://colab.research.google.com/github/vanderbilt-data-science/lo-achievement/blob/main/prompt_with_context.ipynb) notebook."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6Gf-_aZVPA_S"
},
"source": [
"# Code Setup\n",
"Run the following cells to setup the rest of the environment for prompting. In the following section, we set up the computational environment with imported code, setup your API key access to OpenAI, and loading access to your language model. Note that the following cells may take a long time to run."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6040J5eXPA_T"
},
"source": [
"## Library installation and loading\n",
"The following `pip install` code should be run if you're using Google Colab, or otherwise do not have a computational environment (e.g., _venv_, _conda virtual environment_, _Docker, Singularity, or other container_) with these packages installed."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "7_XCtEMbPA_T",
"outputId": "aa36bcf0-1d11-4947-f96b-d28c67d4e431"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mDEPRECATION: pyodbc 4.0.0-unsupported has a non-standard version number. pip 23.3 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of pyodbc or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n",
"\u001b[0m"
]
}
],
"source": [
"# run this code if you're using Google Colab or don't have these packages installed in your computing environment\n",
"! pip install -q langchain openai gradio numpy tiktoken"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "6fdfMar8PA_U"
},
"outputs": [],
"source": [
"# import required libraries\n",
"import numpy as np\n",
"import getpass\n",
"import os\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.chains import RetrievalQA\n",
"from langchain.schema import SystemMessage, HumanMessage, AIMessage"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5iI75yjaPA_V"
},
"source": [
"## API and model setup\n",
"\n",
"Use these cells to load the API keys required for this notebook and create a basic OpenAI LLM model. The code below uses the variable you created above when you input your API Key."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "8IgmjGEFPA_V",
"outputId": "5ac82647-2f93-4bd3-9284-e18dd04b1c81"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"··········\n"
]
}
],
"source": [
"# Set up OpenAI API Key\n",
"openai_api_key = getpass.getpass()\n",
"os.environ[\"OPENAI_API_KEY\"] = openai_api_key\n",
"\n",
"llm = ChatOpenAI(model='gpt-3.5-turbo-16k')\n",
"messages = [\n",
" SystemMessage(content=\"You are a world-class tutor helping students to perform better on oral and written exams though interactive experiences.\"),\n",
" HumanMessage(content=\"\")\n",
"]\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Zlx1_Y8rYGn3"
},
"source": [
"# Add your context and assign the prefix to your query.\n",
"The query assigned here serves as an example."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "g_CAvacjEuCd"
},
"outputs": [],
"source": [
"context = \"\"\" Two roads diverged in a yellow wood,\n",
"And sorry I could not travel both\n",
"And be one traveler, long I stood\n",
"And looked down one as far as I could\n",
"To where it bent in the undergrowth;\n",
"Then took the other, as just as fair,\n",
"And having perhaps the better claim,\n",
"Because it was grassy and wanted wear;\n",
"Though as for that the passing there\n",
"Had worn them really about the same,\n",
"And both that morning equally lay\n",
"In leaves no step had trodden black.\n",
"Oh, I kept the first for another day!\n",
"Yet knowing how way leads on to way,\n",
"I doubted if I should ever come back.\n",
"I shall be telling this with a sigh\n",
"Somewhere ages and ages hence:\n",
"Two roads diverged in a wood, and I—\n",
"I took the one less traveled by,\n",
"And that has made all the difference.\n",
"—-Robert Frost—-\n",
"Education Place: http://www.eduplace.com \"\"\"\n",
"\n",
"# Query prefix\n",
"query_prefix = \"The following text should be used as the basis for the instructions which follow: \" + context + '\\n'\n",
"\n",
"# Query\n",
"query = \"\"\"Please design a 5 question quiz about Robert Frost's \"Road Not Taken\" which reflects the learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes. The questions should be multiple choice.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response.\n",
"If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional\n",
"chances to respond until I get the correct choice. Explain why the correct choice is right. \"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hLMJRXc8PA_W"
},
"source": [
"# A guide to prompting for self-study\n",
"In this section, we provide a number of different approaches for using AI to help you assess and explain the knowledge of your document. Start by interacting with the model and then try out the rest of the prompts!"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jNBwByBFaJVP"
},
"source": [
"## Interact with the model\n",
"\n",
"Now that your vector store is created, you can begin interacting with the model! Below, we have a comprehensive list of examples using different question types, but feel free to use this code block to experiment with the model.\n",
"\n",
"Input your prompt into the empty string in the code cell. See example below:\n",
"\n",
"\n",
"\n",
"```\n",
"query = 'Your Prompt Here'\n",
"```\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "3fPd2b3yUZic"
},
"outputs": [],
"source": [
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cskXB5p5DupT"
},
"outputs": [],
"source": [
"query = 'Your Prompt Here'\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "FLy4qDuWclWF"
},
"source": [
"### Our example using query from cell 103\n",
"\n",
"Run the following code to see a simple example using the prompt defined in an earlier cell (#103)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4QBBlJI-adPf",
"outputId": "0d421ad5-74ca-40eb-bd68-afcb47768275"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem \"Road Not Taken\"?\n",
"\n",
"a) Robert Frost\n",
"b) A traveler\n",
"c) The poet\\'s friend\n",
"d) The reader\n"
]
}
],
"source": [
"# Experiment with interacting with the model by inputting your own prompts into the empty string below.\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KYro6H82bENS"
},
"source": [
"## Types of Questions and Prompts\n",
"\n",
"Below is a comprehensive list of question types and prompt templates designed by our team. There are also example code blocks, where you can see how the model performed with the example and try it for yourself using the prompt template."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WAUSc7qJPA_X"
},
"source": [
"### Multiple Choice\n",
"\n",
"Prompt: The following text should be used as the basis for the instructions which follow: {context}. Please design a {number of questions} question quiz about {name or reference to context} which reflects the learning objectives: {list of learning objectives}. The questions should be multiple choice. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "nFMRDL4cPA_X",
"outputId": "b341fcb8-49df-43e6-9810-7ff3f232949e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem \"Road Not Taken\"?\n",
"\n",
"A) Robert Frost\n",
"B) The reader\n",
"C) The traveler\n",
"D) The poet\n"
]
}
],
"source": [
"# Multiple choice code example\n",
"query = \"\"\"Please design a 5 question quiz about Robert Frost's \"Road Not Taken\" which reflects the learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes. The questions should be multiple choice.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response\n",
"If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional\n",
"chances to respond until I get the correct choice. Explain why the correct choice is right. \"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WkSIU94GPA_Y"
},
"source": [
"### Short Answer\n",
"\n",
"Prompt: Please design a {number of questions} question quiz about {context} which reflects the learning objectives: {list of learning objectives}. The questions should be short answer. Expect the correct answers to be {anticipated length} long. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "enC8ydfEPA_Y",
"outputId": "639efa60-3304-4b63-c0e8-a975d2d7dfaf"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem \"Road Not Taken\"?\n"
]
}
],
"source": [
"# Short answer code example\n",
"query = \"\"\" Please design a 5-question quiz about Robert Frost's\n",
"\"Road Not Taken\" which reflects the learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes.\n",
"The questions should be short answer. Expect the correct answers to be\n",
"1-2 sentences long.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response\n",
"If I get any part of the answer wrong,\n",
"provide me with an explanation of why it was incorrect,\n",
"and then give me additional chances to respond until I get the correct choice. \"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Ta4A527kPA_Y"
},
"source": [
"### Fill-in-the-blank\n",
"\n",
"Prompt: Create a {number of questions} question fill in the blank quiz refrencing {context}. The quiz should reflect the learning objectives: {learning objectives}. The \"blank\" part of the question should appear as \"________\". The answers should reflect what word(s) should go in the blank an accurate statement.\n",
"\n",
"An example is the follow: \"The author of the book is \"________.\"\n",
"\n",
"The question should be a statement. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "szMOxEoiPA_Z",
"outputId": "0c4c823b-6f07-4ba0-cbf3-54b3e28d0d6c"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: In \"The Road Not Taken,\" the narrator comes to a point where two roads ____________ in a yellow wood.\n"
]
}
],
"source": [
"# Fill in the blank code example\n",
"query = \"\"\" Create a 5 question fill in the blank quiz refrencing Robert Frost's \"The Road Not Taken.\"\n",
"The \"blank\" part of the question should appear as \"________\". The answers should reflect what word(s) should go in the blank an accurate statement.\n",
"An example is the follow: \"The author of the book is ______.\" The question should be a statement.\n",
"The quiz should reflect the learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response\n",
"If I answer incorrectly, please explain why my answer is incorrect. \"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yEwzAB28PA_Z"
},
"source": [
"### Sequencing\n",
"\n",
"Prompt: Please develop a {number of questions} question questionnaire that will ask me to recall the steps involved in the following learning objectives in regard to {context}: {learning objectives}. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional chances to respond until I get the correct choice. After I respond, explain their sequence to me."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3YRyhhWtPA_Z",
"outputId": "7e26ed3b-99c7-4577-c808-fb85c3e11b4c"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem?\n"
]
}
],
"source": [
"# Sequence example\n",
"query = \"\"\" Please develop a 5 question questionnaire that will ask me to recall the steps involved in the following learning objectives in regard to Robert Frost's \"The Road Not Taken\":\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response.\n",
"After I respond, explain their sequence to me.\"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0DGBiJofPA_Z"
},
"source": [
"### Relationships/drawing connections\n",
"\n",
"Prompt: Please design a {number of questions} question quiz that asks me to explain the relationships that exist within the following learning objectives, referencing {context}: {learning objectives}. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Mw3RBpsnPA_a",
"outputId": "3f721340-7fef-4617-cc2c-2420779ecb2d"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Identify the key elements of the poem: narrator, setting, and underlying message.\n"
]
}
],
"source": [
"# Relationships example\n",
"query = \"\"\" Please design a 5 question quiz that asks me to explain the relationships that exist within the following learning objectives, referencing Robert Frost's \"The Road Not Taken\":\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response.\"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4YO3wCTwPA_a"
},
"source": [
"### Concepts and Definitions\n",
"\n",
"Prompt: Design a {number of questions} question quiz that asks me about definitions related to the following learning objectives: {learning objectives} - based on {context}\".\n",
"Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right.\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TbvJPhkmPA_a",
"outputId": "f174e720-a31a-4476-8701-36ed9f637770"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem \"The Road Not Taken\"?\n",
"\n",
"Please provide your response.\n"
]
}
],
"source": [
"# Concepts and definitions example\n",
"query = \"\"\" Design a 5 question quiz that asks me about definitions related to the following learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message, and\n",
"2. Understand the literary devices used in poetry and their purposes - based on Robert Frost's \"The Road Not Taken\".\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response\n",
"Once I write out my response, provide me with your own response, highlighting why my answer is correct or incorrect.\"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vc-llAgfPA_a"
},
"source": [
"### Real Word Examples\n",
"\n",
"Prompt: Demonstrate how {context} can be applied to solve a real-world problem related to the following learning objectives: {learning objectives}. Ask me questions regarding this theory/concept.\n",
"\n",
"Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "sSwRLkR8PA_a",
"outputId": "4d91df15-b7b8-4bc9-d1b2-3af7e629be4f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem?\n"
]
}
],
"source": [
"# Real word example\n",
"query = \"\"\" Demonstrate how Robert Frost’s “The Road Not Taken” can be applied to solve a real-world problem. Ask me questions regarding\n",
"this theory/concept and relate them to the following learning objectives:\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response\n",
"\"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2y6gHhGKPA_b"
},
"source": [
"### Randomized Question Types\n",
"\n",
"Prompt: Please generate a high-quality assessment consisting of {number of questions} varying questions, each of different types (open-ended, multiple choice, etc.), to determine if I achieved the following learning objectives in regards to {context}: {learning objectives}.\n",
"\n",
"Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "xC4t4WMwPA_b",
"outputId": "331b1ef7-ef34-4d21-ddbd-e2ebae1d2fd4"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: \n",
"Identify the narrator of the poem \"The Road not Taken\" by Robert Frost.\n",
"\n",
"Question 2: \n",
"What is the setting of the poem \"The Road not Taken\" by Robert Frost?\n",
"\n",
"Question 3: \n",
"What is the underlying message or theme of the poem \"The Road not Taken\" by Robert Frost?\n",
"\n",
"Question 4 (Multiple Choice):\n",
"Which literary device is NOT used in the poem \"The Road not Taken\" by Robert Frost?\n",
"a) Metaphor\n",
"b) Simile\n",
"c) Alliteration\n",
"d) Personification\n",
"\n",
"Question 5 (Open-ended):\n",
"Provide an example of a literary device used in the poem \"The Road not Taken\" by Robert Frost and explain its purpose.\n"
]
}
],
"source": [
"# Randomized question types\n",
"query = \"\"\" Please generate a high-quality assessment consisting of 5 varying questions,\n",
"each of different types (open-ended, multiple choice, etc.),\n",
"to determine if I achieved the following learning objectives in regards to Robert Frost’s “The Road not Taken\":\n",
"1. Identify the key elements of the poem: narrator, setting, and underlying message.\n",
"2. Understand the literary devices used in poetry and their purposes. If I answer incorrectly for any of the questions,\n",
"please explain why my answer is incorrect.\n",
"Provide one question at a time, and wait for my response before providing me with feedback.\n",
"Again, while the quiz asks for 5 questions, you should\n",
"only provide ONE question in you initial response. Do not include the answer in your response.\n",
"\"\"\"\n",
"\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ndo_cdWYPA_b"
},
"source": [
"### Quantiative evaluation the correctness of a student's answer\n",
"\n",
"Prompt: (A continuation of the previous chat) Please generate the main points of the student’s answer to the previous question, and evaluate on a scale of 1 to 5 how comprehensive the student’s answer was in relation to the learning objectives, and explain why he or she received this rating, including what was missed in his or her answer if the student’s answer wasn’t complete.\n"
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WhhNI0FZPA_b",
"outputId": "fb037251-2448-44e7-acef-3e6a28da7cb3"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Question 1: Who is the narrator of the poem \"The Road not Taken\"?\n",
"a) Robert Frost\n",
"b) The traveler\n",
"c) The reader\n",
"d) The poet\\'s imagination\n"
]
}
],
"source": [
"# qualitative evaluation\n",
"qualitative_query = \"\"\" Please generate the main points of the student’s answer to the previous question,\n",
" and evaluate on a scale of 1 to 5 how comprehensive the student’s answer was in relation to the learning objectives,\n",
" and explain why he or she received this rating, including what was missed in his or her answer if the student’s answer wasn’t complete.\"\"\"\n",
"\n",
"# Note that this uses the previous result and query in the context\n",
"def prompt_define(query, prefix, context):\n",
" prompt = (query + prefix)\n",
" prompt = prompt + context\n",
" return prompt\n",
"\n",
"prompt = prompt_define(query, query_prefix, context)\n",
"\n",
"def get_result(prompt):\n",
" messages[1] = HumanMessage(content=prompt)\n",
" result = llm(messages)\n",
" str_result = str(result)\n",
" import re\n",
" str_result = str_result.replace(r'\\n', '\\n')\n",
" str_result = str_result.replace(\"content='\", \"\")\n",
" str_result = str_result.replace(\"' additional_kwargs={} example=False\", \"\")\n",
" return str_result\n",
"\n",
"result = get_result(prompt)\n",
"\n",
"print(result)"
]
}
],
"metadata": {
"colab": {
"include_colab_link": true,
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.11.5 64-bit",
"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.11.5"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
|