Updated explanations and tips
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
"source": [
|
||||
"## First: if you need a refresher on the foundations\n",
|
||||
"\n",
|
||||
"I'm going to defer to an AI friend for this, because these explanations are so well written with great examples. Copy and paste the code examples into a new cell to give them a try.\n",
|
||||
"I'm going to defer to an AI friend for this, because these explanations are so well written with great examples. Copy and paste the code examples into a new cell to give them a try. Pick whichever section(s) you'd like to brush up on.\n",
|
||||
"\n",
|
||||
"**Python imports:** \n",
|
||||
"https://chatgpt.com/share/672f9f31-8114-8012-be09-29ef0d0140fb\n",
|
||||
@@ -40,8 +40,14 @@
|
||||
"**Python lists, dicts and sets**, including the `get()` method: \n",
|
||||
"https://chatgpt.com/share/672fa225-3f04-8012-91af-f9c95287da8d\n",
|
||||
"\n",
|
||||
"**Python files** including modes, encoding, context managers, Path, glob.glob: \n",
|
||||
"https://chatgpt.com/share/673b53b2-6d5c-8012-a344-221056c2f960\n",
|
||||
"\n",
|
||||
"**Python classes:** \n",
|
||||
"https://chatgpt.com/share/672fa07a-1014-8012-b2ea-6dc679552715"
|
||||
"https://chatgpt.com/share/672fa07a-1014-8012-b2ea-6dc679552715\n",
|
||||
"\n",
|
||||
"**Pickling Python objects and converting to JSON:** \n",
|
||||
"https://chatgpt.com/share/673b553e-9d0c-8012-9919-f3bb5aa23e31"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -123,7 +129,7 @@
|
||||
"source": [
|
||||
"# But you may not know that you can do this to create dictionaries, too:\n",
|
||||
"\n",
|
||||
"fruit_mapping = {fruit:fruit.upper() for fruit in fruits}\n",
|
||||
"fruit_mapping = {fruit: fruit.upper() for fruit in fruits}\n",
|
||||
"fruit_mapping"
|
||||
]
|
||||
},
|
||||
@@ -147,7 +153,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fruit_mapping_unless_starts_with_a = {fruit:fruit.upper() for fruit in fruits if not fruit.startswith('A')}\n",
|
||||
"fruit_mapping_unless_starts_with_a = {fruit: fruit.upper() for fruit in fruits if not fruit.startswith('A')}\n",
|
||||
"fruit_mapping_unless_starts_with_a"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -43,9 +43,28 @@
|
||||
"\n",
|
||||
"If you're already comfortable with today's material, please hang in there; you can move swiftly through the first few labs - we will get much more in depth as the weeks progress.\n",
|
||||
"\n",
|
||||
"## Business value of these exercises\n",
|
||||
"\n",
|
||||
"A final thought. While I've designed these notebooks to be educational, I've also tried to make them enjoyable. We'll do fun things like have LLMs tell jokes and argue with each other. But fundamentally, my goal is to teach skills you can apply in business. I'll explain business implications as we go, and it's worth keeping this in mind: as you build experience with models and techniques, think of ways you could put this into action at work today. Please do contact me if you'd like to discuss more or if you have ideas to bounce off me."
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../important.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#900;\">Please read - important note</h2>\n",
|
||||
" <span style=\"color:#900;\">The way I collaborate with you may be different to other courses you've taken. I prefer not to type code while you watch. Rather, I execute Jupyter Labs, like this, and give you an intuition for what's going on. My suggestion is that you do this with me, either at the same time, or (perhaps better) right afterwards. Add print statements to understand what's going on, and then come up with your own variations. If you have a Github account, use this to showcase your variations. Not only is this essential practice, but it demonstrates your skills to others, including perhaps future clients or employers...</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>\n",
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../business.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#181;\">Business value of these exercises</h2>\n",
|
||||
" <span style=\"color:#181;\">A final thought. While I've designed these notebooks to be educational, I've also tried to make them enjoyable. We'll do fun things like have LLMs tell jokes and argue with each other. But fundamentally, my goal is to teach skills you can apply in business. I'll explain business implications as we go, and it's worth keeping this in mind: as you build experience with models and techniques, think of ways you could put this into action at work today. Please do contact me if you'd like to discuss more or if you have ideas to bounce off me.</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -136,9 +155,6 @@
|
||||
"# If you're not familiar with Classes, check out the \"Intermediate Python\" notebook\n",
|
||||
"\n",
|
||||
"class Website:\n",
|
||||
" \"\"\"\n",
|
||||
" A utility class to represent a Website that we have scraped\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def __init__(self, url):\n",
|
||||
" \"\"\"\n",
|
||||
@@ -160,7 +176,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Let's try one out\n",
|
||||
"# Let's try one out. Change the website and add print statements to follow along.\n",
|
||||
"\n",
|
||||
"ed = Website(\"https://edwarddonner.com\")\n",
|
||||
"print(ed.title)\n",
|
||||
@@ -267,6 +283,8 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Try this out, and then try for a few more websites\n",
|
||||
"\n",
|
||||
"messages_for(ed)"
|
||||
]
|
||||
},
|
||||
@@ -371,11 +389,59 @@
|
||||
"id": "c951be1a-7f1b-448f-af1f-845978e47e2c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Business Applications\n",
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../business.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#181;\">Business applications</h2>\n",
|
||||
" <span style=\"color:#181;\">In this exercise, you experienced calling the Cloud API of a Frontier Model (a leading model at the frontier of AI) for the first time. We will be using APIs like OpenAI at many stages in the course, in addition to building our own LLMs.\n",
|
||||
"\n",
|
||||
"In this exercise, you experienced calling the API of a Frontier Model (a leading model at the frontier of AI) for the first time. This is broadly applicable across Gen AI use cases and we will be using APIs like OpenAI at many stages in the course, in addition to building our own LLMs.\n",
|
||||
"More specifically, we've applied this to Summarization - a classic Gen AI use case to make a summary. This can be applied to any business vertical - summarizing the news, summarizing financial performance, summarizing a resume in a cover letter - the applications are limitless. Consider how you could apply Summarization in your business, and try prototyping a solution.</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>\n",
|
||||
"\n",
|
||||
"More specifically, we've applied this to Summarization - a classic Gen AI use case to make a summary. This can be applied to any business vertical - summarizing the news, summarizing financial performance, summarizing a resume in a cover letter - the applications are limitless. Consider how you could apply Summarization in your business, and try prototyping a solution."
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../important.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#900;\">Before you continue - now try yourself</h2>\n",
|
||||
" <span style=\"color:#900;\">Use the cell below to make your own simple commercial example. Stick with the summarization use case for now. Here's an idea: write something that will take the contents of an email, and will suggest an appropriate short subject line for the email. That's the kind of feature that might be built into a commercial email tool.</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "00743dac-0e70-45b7-879a-d7293a6f68a6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Step 1: Create your prompts\n",
|
||||
"\n",
|
||||
"system_prompt = \"something here\"\n",
|
||||
"user_prompt = \"\"\"\n",
|
||||
" Lots of text\n",
|
||||
" Can be pasted here\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"# Step 2: Make the messages list\n",
|
||||
"\n",
|
||||
"messages = [] # fill this in\n",
|
||||
"\n",
|
||||
"# Step 3: Call OpenAI\n",
|
||||
"\n",
|
||||
"response =\n",
|
||||
"\n",
|
||||
"# Step 4: print the result\n",
|
||||
"\n",
|
||||
"print("
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -29,7 +29,10 @@
|
||||
"You should see the message `Ollama is running`. \n",
|
||||
"\n",
|
||||
"If not, bring up a new Terminal (Mac) or Powershell (Windows) and enter `ollama serve` \n",
|
||||
"Then try [http://localhost:11434/](http://localhost:11434/) again."
|
||||
"And in another Terminal (Mac) or Powershell (Windows), enter `ollama pull llama3.2` \n",
|
||||
"Then try [http://localhost:11434/](http://localhost:11434/) again.\n",
|
||||
"\n",
|
||||
"If Ollama is slow on your machine, try using `llama3.2:1b` as an alternative. Run `ollama pull llama3.2:1b` from a Terminal or Powershell, and change the code below from `MODEL = \"llama3.2\"` to `MODEL = \"llama3.2:1b\"`"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -124,14 +127,6 @@
|
||||
"print(response['message']['content'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9a611b05-b5b0-4c83-b82d-b3a39ffb917d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1622d9bb-5c68-4d4e-9ca4-b492c751f898",
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
"load_dotenv()\n",
|
||||
"api_key = os.getenv('OPENAI_API_KEY')\n",
|
||||
"\n",
|
||||
"if api_key and api_key[:8]=='sk-proj-':\n",
|
||||
"if api_key and api_key.startswith('sk-proj-') and len(api_key)>10:\n",
|
||||
" print(\"API key looks good so far\")\n",
|
||||
"else:\n",
|
||||
" print(\"There might be a problem with your API key? Please visit the troubleshooting notebook!\")\n",
|
||||
@@ -391,19 +391,45 @@
|
||||
"id": "a27bf9e0-665f-4645-b66b-9725e2a959b5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Business Applications\n",
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../business.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#181;\">Business applications</h2>\n",
|
||||
" <span style=\"color:#181;\">In this exercise we extended the Day 1 code to make multiple LLM calls, and generate a document.\n",
|
||||
"\n",
|
||||
"In this exercise we extended the Day 1 code to make multiple LLM calls, and generate a document.\n",
|
||||
"This is perhaps the first example of Agentic AI design patterns, as we combined multiple calls to LLMs. This will feature more in Week 2, and then we will return to Agentic AI in a big way in Week 8 when we build a fully autonomous Agent solution.\n",
|
||||
"\n",
|
||||
"In terms of techniques, this is perhaps the first example of Agentic AI design patterns, as we combined multiple calls to LLMs. This will feature more in Week 2, and then we will return to Agentic AI in a big way in Week 8 when we build a fully autonomous Agent solution.\n",
|
||||
"\n",
|
||||
"In terms of business applications - generating content in this way is one of the very most common Use Cases. As with summarization, this can be applied to any business vertical. Write marketing content, generate a product tutorial from a spec, create personalized email content, and so much more. Explore how you can apply content generation to your business, and try making yourself a proof-of-concept prototype."
|
||||
"Generating content in this way is one of the very most common Use Cases. As with summarization, this can be applied to any business vertical. Write marketing content, generate a product tutorial from a spec, create personalized email content, and so much more. Explore how you can apply content generation to your business, and try making yourself a proof-of-concept prototype.</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "14b2454b-8ef8-4b5c-b928-053a15e0d553",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<table style=\"margin: 0; text-align: left;\">\n",
|
||||
" <tr>\n",
|
||||
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
||||
" <img src=\"../important.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <h2 style=\"color:#900;\">Before you move to Week 2 (which is tons of fun)</h2>\n",
|
||||
" <span style=\"color:#900;\">Please see the week1 EXERCISE notebook for your challenge for the end of week 1. This will give you some essential practice working with Frontier APIs, and prepare you well for Week 2.</span>\n",
|
||||
" </td>\n",
|
||||
" </tr>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "22e878f1-08fe-4465-b50c-869352174eae",
|
||||
"id": "55b2620c-35ee-4d42-a4d9-90fe98dbef02",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
"4. Kernel menu >> Restart Kernel and Clear Outputs of All Cells\n",
|
||||
"5. Come back to this notebook and try the cell below again.\n",
|
||||
"\n",
|
||||
"If **that** doesn't work, then please contact me! I'll respond quickly, and we'll figure it out."
|
||||
"If **that** doesn't work, then please contact me! I'll respond quickly, and we'll figure it out. If you used Anaconda, it might be that for some reason your environment is corrupted, in which case the simplest fix is to use the virtualenv approach instead (Part 2B in the setup guides)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -46,6 +46,8 @@
|
||||
"source": [
|
||||
"# This should run with no output - no import errors.\n",
|
||||
"# Import errors might indicate that you started jupyter lab without your environment activated? See SETUP part 5.\n",
|
||||
"# Or you might need to restart your Kernel and Jupyter Lab.\n",
|
||||
"# Or it's possible that something is wrong with Anaconda, in which case we may have to use virtualenv instead.\n",
|
||||
"\n",
|
||||
"from openai import OpenAI"
|
||||
]
|
||||
@@ -60,7 +62,9 @@
|
||||
"Let's check your .env file exists and has the OpenAI key set properly inside it. \n",
|
||||
"Please run this code and check that it prints a successful message, otherwise follow its instructions.\n",
|
||||
"\n",
|
||||
"Note that the `.env` file won't show up in your Jupyter Lab file browser, because Jupyter hides files that start with a dot for your security; they're considered hidden files. If you need to change the name, you'll need to use a command terminal or File Explorer (PC) / Finder Window (Mac). Ask ChatGPT if that's giving you problems, or email me!"
|
||||
"Note that the `.env` file won't show up in your Jupyter Lab file browser, because Jupyter hides files that start with a dot for your security; they're considered hidden files. If you need to change the name, you'll need to use a command terminal or File Explorer (PC) / Finder Window (Mac). Ask ChatGPT if that's giving you problems, or email me!\n",
|
||||
"\n",
|
||||
"If you're having challenges creating the `.env` file, we can also do it with code! See the cell after the next one."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -102,6 +106,45 @@
|
||||
" print(file.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "105f9e0a-9ff4-4344-87c8-e3e41bc50869",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Fallback plan - python code to create the .env file for you\n",
|
||||
"\n",
|
||||
"Only run the next cell if you're having problems making the .env file. \n",
|
||||
"Replace the text in the first line of code with your key from OpenAI."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ab9ea6ef-49ee-4899-a1c7-75a8bd9ac36b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Only run this code in this cell if you want to have a .env file created for you!\n",
|
||||
"\n",
|
||||
"make_me_a_file_with_this_key = \"put your key here inside these quotes.. it should start sk-proj-\"\n",
|
||||
"\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"parent_dir = Path(\"..\")\n",
|
||||
"env_path = parent_dir / \".env\"\n",
|
||||
"\n",
|
||||
"if env_path.exists():\n",
|
||||
" print(\"There is already a .env file - if you want me to create a new one, please delete the existing one first\")\n",
|
||||
"else:\n",
|
||||
" try:\n",
|
||||
" with env_path.open(mode='w', encoding='utf-8') as env_file:\n",
|
||||
" env_file.write(f\"OPENAI_API_KEY={make_me_a_file_with_this_key}\")\n",
|
||||
" print(f\"Successfully created the .env file at {env_path}\")\n",
|
||||
" print(\"Now rerun the previous cell to confirm that the file is created and the key is correct.\")\n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\"An error occurred while creating the .env file: {e}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0ba9420d-3bf0-4e08-abac-f2fbf0e9c7f1",
|
||||
@@ -109,7 +152,7 @@
|
||||
"source": [
|
||||
"# Step 3\n",
|
||||
"\n",
|
||||
"Now let's check that your API key is correct set up in your `.env` file.\n",
|
||||
"Now let's check that your API key is correct set up in your `.env` file, and available using the dotenv package.\n",
|
||||
"Try running the next cell."
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user