More troubleshooting and setup tips, and some improvements to flagship Week 8 project

This commit is contained in:
Edward Donner
2024-10-20 15:24:40 -04:00
parent ced435c95a
commit 0a64893188
10 changed files with 247 additions and 187 deletions

View File

@@ -9,6 +9,8 @@
"\n",
"Let's build a useful LLM solution - in a matter of minutes.\n",
"\n",
"By the end of this course, you will have built an autonomous Agentic AI solution with 7 agents that collaborate to solve a business problem. All in good time! We will start with something smaller...\n",
"\n",
"Our goal is to code a new kind of Web Browser. Give it a URL, and it will respond with a summary. The Reader's Digest of the internet!!\n",
"\n",
"Before starting, be sure to have followed the instructions in the \"README\" file, including creating your API key with OpenAI and adding it to the `.env` file.\n",
@@ -24,6 +26,10 @@
"If you have any problems at all, please do reach out. \n",
"I'm available through the platform, or at ed@edwarddonner.com, or at https://www.linkedin.com/in/eddonner/ if you'd like to connect.\n",
"\n",
"## More troubleshooting\n",
"\n",
"Please see the [troubleshooting](troubleshooting.ipynb) notebook in this folder for more ideas!\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."
@@ -64,7 +70,8 @@
"- Click Create secret key, and use that new key in the code and the `.env` file (it might take a few minutes to activate)\n",
"- Do a Kernel >> Restart kernel, and execute the cells in this Jupyter lab starting at the top\n",
"4. As a fallback, replace the line `openai = OpenAI()` with `openai = OpenAI(api_key=\"your-key-here\")` - while it's not recommended to hard code tokens in Jupyter lab, because then you can't share your lab with others, it's a workaround for now\n",
"5. Contact me! Message me or email ed@edwarddonner.com and we will get this to work.\n",
"5. See the [troubleshooting](troubleshooting.ipynb) notebook in this folder for more instructions\n",
"6. Contact me! Message me or email ed@edwarddonner.com and we will get this to work.\n",
"\n",
"Any concerns about API costs? See my notes in the README - costs should be minimal, and you can control it at every point."
]

170
week1/troubleshooting.ipynb Normal file
View File

@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2a793b1d-a0a9-404c-ada6-58937227cfce",
"metadata": {},
"source": [
"# Oh dear!\n",
"\n",
"If you've got here, then you're still having problems setting up your environment. I'm so sorry! Hang in there and we should have you up and running in no time.\n",
"\n",
"Setting up a Data Science environment can be challenging because there's a lot going on under the hood. But we will get there.\n",
"\n",
"And please remember - I'm standing by to help out. Message me or email ed@edwarddonner.com and I'll get on the case.\n"
]
},
{
"cell_type": "markdown",
"id": "f5190688-205a-46d1-a0dc-9136a42ad0db",
"metadata": {},
"source": [
"# Step 1\n",
"\n",
"Try running the next cell (click in the cell under this one and hit shift+return).\n",
"\n",
"If this doesn't work, then you're not running in an \"activated\" environment. Please check back in the [README](../README.md) for setting up the Anaconda (or virtualenv) environment and activating it, before running `jupyter lab`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c78b7d9-1eea-412d-8751-3de20c0f6e2f",
"metadata": {},
"outputs": [],
"source": [
"# This should run with no output - no import errors:\n",
"\n",
"from openai import OpenAI"
]
},
{
"cell_type": "markdown",
"id": "0ba9420d-3bf0-4e08-abac-f2fbf0e9c7f1",
"metadata": {},
"source": [
"# Step 2\n",
"\n",
"Now let's check that your API key is correct set up in your `.env` file.\n",
"Try running the next cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ee8e613-5a6e-4d1f-96ef-91132da545c8",
"metadata": {},
"outputs": [],
"source": [
"# This should print your API key to the output\n",
"\n",
"import os\n",
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"print(\"My key is\", os.getenv(\"OPENAI_API_KEY\"))"
]
},
{
"cell_type": "markdown",
"id": "f403e515-0e7d-4be4-bb79-5a102dbd6c94",
"metadata": {},
"source": [
"## It should print something like:\n",
"\n",
"`My key is sk-proj-blahblahblah`\n",
"\n",
"If it didn't print a key, then it's not able to find a file called `.env` in the `llm_engineering` folder. \n",
"Double check those steps in the instructions. Is it possible that `.env` is actually called `.env.txt`? In Windows, you may need to change a setting in the File Explorer to ensure that file extensions are showing. Or you will see them if you type `dir` in the `llm_engineering` directory.\n",
"\n",
"Worst case, if you're not able to get this part to work, it's not a big deal. You'll just have to paste your key into the Jupyter Notebook (see below for an example), and be sure to remove it before you share the Notebook with anybody else."
]
},
{
"cell_type": "markdown",
"id": "42afad1f-b0bf-4882-b469-7709060fee3a",
"metadata": {},
"source": [
"# Step 3\n",
"\n",
"Now run the below code and you will hopefully see that GPT can handle basic arithmetic!!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cccb58e7-6626-4033-9dc1-e7e3ff742f6b",
"metadata": {},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"\n",
"my_api_key = \"REPLACE THIS TEXT WITH YOUR OPENAI API KEY WITHIN THE QUOTE MARKS - it should start sk-proj-\"\n",
"\n",
"openai = OpenAI(api_key=my_api_key)\n",
"completion = openai.chat.completions.create(\n",
" model='gpt-4o-mini',\n",
" messages=[{\"role\":\"user\", \"content\": \"What's 2+2?\"}],\n",
")\n",
"print(completion.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "81046a77-c359-4388-929f-ffc8ad5cb93c",
"metadata": {},
"source": [
"# If this didn't work\n",
"\n",
"Then there's something up with your API key!\n",
"\n",
"First check this webpage to make sure you have a positive credit balance.\n",
"OpenAI requires that you have a positive credit balance and it has minimums. Contact me if this is a problem - I can likely share a key with a small limit.\n",
"\n",
"https://platform.openai.com/settings/organization/billing/overview\n",
"\n",
"Also try creating a new key (button on the top right) here:\n",
"\n",
"https://platform.openai.com/api-keys\n",
"\n",
"And note that sometimes OpenAI seems to take a few minutes to give you access after you try.\n",
"\n",
"## If all else fails:\n",
"\n",
"(1) Try pasting your error into ChatGPT or Claude! It's amazing how often they can figure things out\n",
"\n",
"(2) Contact me! ed@edwarddonner.com\n",
"\n",
"Thanks so much.."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42165c99-ec20-460b-b94d-ea1da25b2a0a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}