{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true, "id": "OHtb7Wkf1gas" }, "source": [ "" ] }, { "cell_type": "markdown", "metadata": { "id": "Tq2RwQr71gaz" }, "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": "code", "execution_count": 1, "metadata": { "id": "ImAL1pvx1ga0" }, "outputs": [], "source": [ "#libraries for user setup code\n", "from getpass import getpass\n", "from logging import raiseExceptions" ] }, { "cell_type": "markdown", "metadata": { "id": "03JXTFy21ga2" }, "source": [ "## Helper functions\n", "The following functions help to encapsulate the functionality executed below. The `setup_drives` function below assists with setting up the drives for users to upload files." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "id": "z_l9mjGX1ga3" }, "outputs": [], "source": [ "def setup_drives(upload_set):\n", "\n", " upload_set = upload_set.lower()\n", "\n", " # Colab file upload module\n", " if upload_set == \"local drive\":\n", " from google.colab import files\n", " uploaded = files.upload()\n", " elif upload_set == \"google drive\":\n", " # Mount a Google Drive\n", " from google.colab import drive\n", " drive.mount('/content/drive')\n", " # Raise errors\n", " elif upload_set == '':\n", " raise ValueError(\"You haven't yet defined the upload_settings variable. Go back and read the instructions to make this setting.\")\n", " else:\n", " raise SyntaxError(\"Please check your setting for typos and/or capitalization\")" ] }, { "cell_type": "markdown", "metadata": { "id": "vXWLRdgK1ga4" }, "source": [ "# User Settings\n", "In this section, you'll set your OpenAI API Key (for use with the OpenAI model), configure your environment/files for upload, and upload those files." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "9GfShBqC1ga5" }, "outputs": [], "source": [ "# Run this cell and enter your OpenAI API key when prompted\n", "openai_api_key = getpass()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "id": "Y13LXQa81ga6" }, "outputs": [], "source": [ "# Model name\n", "mdl_name = 'gpt-3.5-turbo-0301'" ] }, { "cell_type": "markdown", "metadata": { "id": "UGHgB0lu1ga7" }, "source": [ "## Define Your Document Source\n", "You may upload your files directly from your computer, or you may choose to do so via your Google Drive. Below, you will find instructions for both methods.\n", "\n", "For either model, begin by setting the `upload_setting` variable to:\n", "* `'Local Drive'` - if you have files that are on your own computer (locally), or\n", "* `'Google Drive'` - if you have files that are stored on Google Drive\n", "\n", "e.g.,\n", "`upload_setting='Google Drive'`.\n", "Don't forget the quotes around your selection!" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "RC8Rpo3G1ga7" }, "outputs": [], "source": [ "## Settings for upload: via local drive or Google Drive\n", "### Please input either \"Google Drive\" or \"Local Drive\" into the empty string\n", "\n", "upload_setting = 'Local Drive'\n", "#upload_setting = 'Google Drive'\n", "#upload_setting = 'Local Drive'" ] }, { "cell_type": "markdown", "metadata": { "id": "A5PTo3lB1ga8" }, "source": [ "
Before Continuing - Make sure you have input your choice of upload into the `upload_setting`` variable above (Options: \"Local Drive\" or \"Google Drive\") as described in the above instructions.
" ] }, { "cell_type": "markdown", "metadata": { "id": "JxrCzAIB1ga8" }, "source": [ "## Upload your Files\n", "Now, you'll upload your files. When you run the below code cell, you'll be able to follow the instructions for local or Google Drive upload described here. If you would like to use our example document (Robert Frost's \"The Road Not Taken\", you can download the file from [this link](https://drive.google.com/drive/folders/1wpEoGACUqyNRYa4zBZeNkqcLJrGQbA53?usp=sharing) and upload via the instructions above.\n", "\n", "**If you selected **\"Local Drive\"** :**\n", "> If you selected Local Drive, you'll need to start by selecting your local files. Run the code cell below. Once the icon appears, click the \"Choose File\". This will direct you to your computer's local drive. Select the file you would like to upload as context. The files will appear in the right sidebar. Then follow the rest of the steps in the \"Uploading Your files (Local Drive and Google Drive)\" below.\n", "\n", "**If you selected **\"Google Drive\"**: **\n", "> If you selected Google Drive, you'll need to start by allowing access to your Google Drive. Run the code cell below. You will be redirected to a window where you will allow access to your Google Drive by logging into your Google Account. Your Drive will appear as a folder in the left side panel. Navigate through your Google Drive until you've found the file that you'd like to upload.\n", "\n", "Your files are now accessible to the code." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "id": "mI7wh4ts1ga9" }, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'google'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[10], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Run this cell then following the instructions to upload your file\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43msetup_drives\u001b[49m\u001b[43m(\u001b[49m\u001b[43mupload_setting\u001b[49m\u001b[43m)\u001b[49m\n", "Cell \u001b[0;32mIn[2], line 7\u001b[0m, in \u001b[0;36msetup_drives\u001b[0;34m(upload_set)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# Colab file upload module\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m upload_set \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlocal drive\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgoogle\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcolab\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m files\n\u001b[1;32m 8\u001b[0m uploaded \u001b[38;5;241m=\u001b[39m files\u001b[38;5;241m.\u001b[39mupload()\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m upload_set \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgoogle drive\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 10\u001b[0m \u001b[38;5;66;03m# Mount a Google Drive\u001b[39;00m\n", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'google'" ] } ], "source": [ "# Run this cell then following the instructions to upload your file\n", "setup_drives(upload_setting)" ] }, { "cell_type": "markdown", "metadata": { "id": "6JF_7_uz1ga9" }, "source": [ "## Setup file path\n", "Now that you've make your files accessible, we need to select the files of interest. To do this, you'll use the Files pane on the left, following the instructions below to get the filepath. Then, you'll paste the filepath between the quotes below to define the `file_path` variable." ] }, { "cell_type": "markdown", "metadata": { "id": "ffV4STf31ga9" }, "source": [ " Step 1. Navigate to the three dots to the right of your file name and click them. | \n",
" Step 2. Once the dropdown appears, select \"Copy Path.\" | \n",
" Step 3. Paste the filepath between the single quotes in the cell below to define the file path. | \n",
"
---|---|---|
\n", " | \n", " | Add your filepath to the cell which follows. Example: file_path = 'content/roadnottaken.txt' | \n",
"