Browse Source

More comments, notes and improvements

pull/40/head
Edward Donner 6 months ago
parent
commit
a7cee4f9aa
  1. 4
      .gitignore
  2. 12
      README.md
  3. 9
      week1/day5.ipynb
  4. 7
      week1/troubleshooting.ipynb
  5. 10
      week2/day1.ipynb
  6. 53
      week2/day2.ipynb

4
.gitignore vendored

@ -169,3 +169,7 @@ products_vectorstore/
# And ignore any pickle files made during the course
*.pkl
# ignore gradio private files
.gradio
/.gradio

12
README.md

@ -15,7 +15,7 @@ https://www.linkedin.com/in/eddonner/
During the course, I'll suggest you try out the leading models at the forefront of progress, known as the Frontier models. I'll also suggest you run open-source models using Google Colab. These services have some charges, but I'll keep cost minimal - like, a few cents at a time.
Please do monitor your API usage to ensure you're comfortable with spend; I've included links below. There's no need to spend anything more than a couple of dollars for the entire course. During Week 7 you have an option to spend a bit more if you're enjoying the process - I spend about $10 myself and the results make me very happy indeed! But it's not necessary in the least; the important part is that you focus on learning.
Please do monitor your API usage to ensure you're comfortable with spend; I've included links below. There's no need to spend anything more than a couple of dollars for the entire course. You may find that AI providers such as OpenAI requires a minimum credit like \$5 for your region; we should only spend a fraction of it, but you'll have plenty of opportunity to put it to good use in your own projects. During Week 7 you have an option to spend a bit more if you're enjoying the process - I spend about $10 myself and the results make me very happy indeed! But it's not necessary in the least; the important part is that you focus on learning.
### How this Repo is organized
@ -28,9 +28,11 @@ The mantra of the course is: the best way to learn is by **DOING**. You should w
## Setup instructions
The recommended approach is to use Anaconda for your environment. Even if you've never used it before, it makes such a difference. Anaconda ensures that you're working with the right version of Python and all your packages are compatible with mine, even if we're on different platforms.
I should confess up-front: setting up a powerful environment to work at the forefront of AI is not as simple as I'd like. For most people these instructions will go great; but in some cases, for whatever reason, you'll hit a problem. Please don't hesitate to reach out - I am here to get you up and running quickly. There's nothing worse than feeling _stuck_. Message me, email me or LinkedIn message me and I will unstick you quickly!
**Update** Some people have had problems with Anaconda - horrors! The idea of Anaconda is to make it really smooth and simple to be working with the same environment. If you hit any problems with the instructions below, please skip to near the end of this README for the alternative approach using `pip`, and hopefully you'll be up and running fast. And please do message me if I can help with anything.
The recommended approach is to use Anaconda for your environment. It's a powerful tool that builds a complete science environment. Anaconda ensures that you're working with the right version of Python and all your packages are compatible with mine, even if we're on different platforms.
**Update** Some people have had problems with Anaconda - horrors! The idea of Anaconda is to make it really smooth and simple to be working with the same environment. If you hit any problems with the instructions below, please skip to near the end of this README for the alternative approach using `pip` with `virtualenv`, and hopefully you'll be up and running fast. And please do message me if I can help with anything.
We'll be mostly using Jupyter Lab in this course. For those new to Jupyter Lab / Jupyter Notebook, it's a delightful Data Science environment where you can simply hit shift+return in any cell to run it; start at the top and work your way down! When we move to Google Colab in Week 3, you'll experience the same interface for Python runtimes in the cloud.
@ -61,7 +63,7 @@ cd C:\Users\YourUsername\Documents\Projects
- Go to the course's GitHub page
- Click the green 'Code' button and copy the URL
- In the Command Prompt, type: `git clone <paste-url-here>`
- In the Command Prompt, type this, replacing everything after the word 'clone' with the copied URL: `git clone <paste-url-here>`
4. **Install Anaconda:**
@ -107,7 +109,7 @@ cd ~/Documents/Projects
- Go to the course's GitHub page
- Click the green 'Code' button and copy the URL
- In Terminal, type: `git clone <paste-url-here>`
- In Terminal, type this, replacing everything after the word 'clone' with the copied URL: `git clone <paste-url-here>`
4. **Install Anaconda:**

9
week1/day5.ipynb

@ -7,6 +7,10 @@
"source": [
"# A full business solution\n",
"\n",
"## Now we will take our project from Day 1 to the next level\n",
"\n",
"### BUSINESS CHALLENGE:\n",
"\n",
"Create a product that builds a Brochure for a company to be used for prospective clients, investors and potential recruits.\n",
"\n",
"We will be provided a company name and their primary website.\n",
@ -60,6 +64,9 @@
"# A class to represent a Webpage\n",
"\n",
"class Website:\n",
" \"\"\"\n",
" A utility class to represent a Website that we have scraped, now with links\n",
" \"\"\"\n",
" url: str\n",
" title: str\n",
" body: str\n",
@ -107,6 +114,8 @@
"It should decide which links are relevant, and replace relative links such as \"/about\" with \"https://company.com/about\". \n",
"We will use \"one shot prompting\" in which we provide an example of how it should respond in the prompt.\n",
"\n",
"This is an excellent use case for an LLM, because it requires nuanced understanding. Imagine trying to code this without LLMs by parsing and analyzing the webpage - it would be very hard!\n",
"\n",
"Sidenote: there is a more advanced technique called \"Structured Outputs\" in which we require the model to respond according to a spec. We cover this technique in Week 8 during our autonomous Agentic AI project."
]
},

7
week1/troubleshooting.ipynb

@ -23,7 +23,7 @@
"\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`."
"If this doesn't work, then you're likely 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`."
]
},
{
@ -76,6 +76,11 @@
"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",
"Nasty gotchas to watch out for: \n",
"- In the .env file, there should be no space between the equals sign and the key. Like: `OPENAI_API_KEY=sk-proj-...`\n",
"- If you copied and pasted your API key from another application, make sure that it didn't replace hyphens in tour key with long dashes\n",
"- If you changed your .env file, you might need to restart your Jupyter \"kernel\" (the python process) to pick up the change via the Kernel menu >> Restart kernel, then rerun the cells from the top.\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."
]
},

10
week2/day1.ipynb

@ -23,6 +23,8 @@
"\n",
"If you haven't done so already, you'll need to create API keys from OpenAI, Anthropic and Google.\n",
"\n",
"**Please note:** if you'd prefer to avoid extra API costs, feel free to skip setting up Anthopic and Google! You can see me do it, and focus on OpenAI for the course.\n",
"\n",
"For OpenAI, visit https://openai.com/api/ \n",
"For Anthropic, visit https://console.anthropic.com/ \n",
"For Google, visit https://ai.google.dev/gemini-api \n",
@ -37,7 +39,9 @@
"GOOGLE_API_KEY=xxxx\n",
"```\n",
"\n",
"OR enter the keys directly in the cells below."
"OR enter the keys directly in the cells below.\n",
"\n",
"You may need to restart the Jupyter Notebook Kernel (the Python process) via the Kernel menu."
]
},
{
@ -259,8 +263,8 @@
"# To be serious! GPT-4o-mini with the original question\n",
"\n",
"prompts = [\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n",
" {\"role\": \"user\", \"content\": \"How do I decide if a business problem is suitable for an LLM solution?\"}\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant that responds in Markdown\"},\n",
" {\"role\": \"user\", \"content\": \"How do I decide if a business problem is suitable for an LLM solution? Please respond in Markdown.\"}\n",
" ]"
]
},

53
week2/day2.ipynb

@ -164,7 +164,7 @@
"metadata": {},
"outputs": [],
"source": [
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\", allow_flagging=\"never\").launch(share=True)"
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\", flagging_mode=\"never\").launch(share=True)"
]
},
{
@ -178,7 +178,7 @@
" fn=shout,\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -194,7 +194,7 @@
" fn=message_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -212,7 +212,7 @@
" fn=message_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -253,7 +253,7 @@
" fn=stream_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -293,11 +293,32 @@
" fn=stream_claude,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
},
{
"cell_type": "markdown",
"id": "bc5a70b9-2afe-4a7c-9bed-2429229e021b",
"metadata": {},
"source": [
"## Minor improvement\n",
"\n",
"I've made a small improvement to this code.\n",
"\n",
"Previously, it had these lines:\n",
"\n",
"```\n",
"for chunk in result:\n",
" yield chunk\n",
"```\n",
"\n",
"There's actually a more elegant way to achieve this (which Python people might call more 'Pythonic'):\n",
"\n",
"`yield from result`"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -312,8 +333,7 @@
" result = stream_claude(prompt)\n",
" else:\n",
" raise ValueError(\"Unknown model\")\n",
" for chunk in result:\n",
" yield chunk"
" yield from result"
]
},
{
@ -327,7 +347,7 @@
" fn=stream_model,\n",
" inputs=[gr.Textbox(label=\"Your message:\"), gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -397,8 +417,7 @@
" result = stream_claude(prompt)\n",
" else:\n",
" raise ValueError(\"Unknown model\")\n",
" for chunk in result:\n",
" yield chunk"
" yield from result"
]
},
{
@ -412,10 +431,10 @@
" fn=stream_brochure,\n",
" inputs=[\n",
" gr.Textbox(label=\"Company name:\"),\n",
" gr.Textbox(label=\"Landing page URL:\"),\n",
" gr.Textbox(label=\"Landing page URL including http:// or https://\"),\n",
" gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n",
" outputs=[gr.Markdown(label=\"Brochure:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
@ -427,6 +446,14 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3d3bf11-e02c-492b-96f1-f4dd7df6f4d7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

Loading…
Cancel
Save