From 7f8697654d4c2e74fe68f971db6c9fdf0d460f8e Mon Sep 17 00:00:00 2001 From: Edward Donner Date: Sun, 8 Dec 2024 22:57:40 -0500 Subject: [PATCH] Package updates, more Ollama, fixes --- README.md | 2 +- environment.yml | 38 +- week1/Guide to Jupyter.ipynb | 2 +- week1/Intermediate Python.ipynb | 2 +- ...Week1-Challenge-Brochure-Translation.ipynb | 2 +- .../day1-selenium-for-javascript-sites.ipynb | 2 +- .../day5-improved-comments-spanish.ipynb | 2 +- .../community-contributions/day5-stream.ipynb | 625 ++++++++++++++++++ week1/day1.ipynb | 68 +- week1/day2 EXERCISE.ipynb | 41 +- week1/day5.ipynb | 20 +- week1/troubleshooting.ipynb | 18 +- week1/week1 EXERCISE.ipynb | 2 +- .../Week2_Day2_AddGeminModel.ipynb | 2 +- .../day1-azure-aws-ollama.ipynb | 12 +- .../day1-with-3way.ipynb | 2 +- week2/community-contributions/day2.ipynb | 2 +- week2/community-contributions/day4.ipynb | 2 +- week2/community-contributions/task1.ipynb | 2 +- week2/day1.ipynb | 52 +- week2/day2.ipynb | 3 +- week2/day3.ipynb | 2 +- week2/day4.ipynb | 9 +- week2/day5.ipynb | 8 +- week2/week2 EXERCISE.ipynb | 2 +- week3/day1.ipynb | 2 +- week3/day2.ipynb | 2 +- week3/day3.ipynb | 2 +- week3/day4.ipynb | 2 +- week3/day5.ipynb | 2 +- week4/day3.ipynb | 24 +- week4/day4.ipynb | 2 +- week4/optimized | Bin 37064 -> 36920 bytes week4/optimized.cpp | 85 ++- ...bsidian files and separate ingestion.ipynb | 2 +- ...king advantage of separate ingestion.ipynb | 2 +- week5/day1.ipynb | 2 +- week5/day2.ipynb | 10 +- week5/day3.ipynb | 2 +- week5/day4.5.ipynb | 17 +- week5/day4.ipynb | 2 +- week5/day5.ipynb | 14 +- week6/day1.ipynb | 2 +- week8/agents/messaging_agent.py | 5 +- week8/day1.ipynb | 2 +- week8/day2.0.ipynb | 2 +- week8/day2.1.ipynb | 2 +- week8/day2.2.ipynb | 2 +- week8/day2.3.ipynb | 2 +- week8/day2.4.ipynb | 2 +- week8/day3.ipynb | 2 +- week8/day4.ipynb | 2 +- week8/day5.ipynb | 22 +- week8/memory.json | 18 + 54 files changed, 1004 insertions(+), 153 deletions(-) create mode 100644 week1/community-contributions/day5-stream.ipynb diff --git a/README.md b/README.md index 8e3b597..94285b3 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ https://edwarddonner.com/2024/11/13/llm-engineering-resources/ ## Instant Gratification instructions for Week 1, Day 1 We will start the course by installing Ollama so you can see results immediately! -1. Download and install Ollama from https://ollama.com +1. Download and install Ollama from https://ollama.com noting that on a PC you might need to have administrator permissions for the install to work properly 2. On a PC, start a Command prompt / Powershell (Press Win + R, type `cmd`, and press Enter). On a Mac, start a Terminal (Applications > Utilities > Terminal). 3. Run `ollama run llama3.2` or for smaller machines try `ollama run llama3.2:1b` 4. If this doesn't work, you may need to run `ollama serve` in another Powershell (Windows) or Terminal (Mac), and try step 3 again diff --git a/environment.yml b/environment.yml index 06afd87..1247085 100644 --- a/environment.yml +++ b/environment.yml @@ -7,44 +7,44 @@ dependencies: - pip - python-dotenv - requests - - beautifulsoup4 - - pydub - numpy - pandas - scipy - pytorch - jupyterlab - ipywidgets - - pyarrow - - anthropic - - google-generativeai - matplotlib - scikit-learn - chromadb - - langchain - - langchain-text-splitters - - langchain-openai - - langchain-experimental - - langchain-chroma - - faiss-cpu - - tiktoken - jupyter-dash - - plotly - - twilio - - duckdb - - feedparser + - sentencepiece + - pyarrow + - faiss-cpu - pip: + - beautifulsoup4 + - plotly + - bitsandbytes - transformers - sentence-transformers - datasets - accelerate - - sentencepiece - - bitsandbytes - openai + - anthropic + - google-generativeai - gradio - gensim - modal - ollama - psutil - setuptools - - speedtest-cli \ No newline at end of file + - speedtest-cli + - langchain + - langchain-core + - langchain-text-splitters + - langchain-openai + - langchain-chroma + - langchain-community + - faiss-cpu + - feedparser + - twilio + - pydub diff --git a/week1/Guide to Jupyter.ipynb b/week1/Guide to Jupyter.ipynb index 6b377db..0f0ddf2 100644 --- a/week1/Guide to Jupyter.ipynb +++ b/week1/Guide to Jupyter.ipynb @@ -372,7 +372,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/Intermediate Python.ipynb b/week1/Intermediate Python.ipynb index e06d533..3cb4d4a 100644 --- a/week1/Intermediate Python.ipynb +++ b/week1/Intermediate Python.ipynb @@ -462,7 +462,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/community-contributions/Week1-Challenge-Brochure-Translation.ipynb b/week1/community-contributions/Week1-Challenge-Brochure-Translation.ipynb index c7e0cf0..e113de5 100644 --- a/week1/community-contributions/Week1-Challenge-Brochure-Translation.ipynb +++ b/week1/community-contributions/Week1-Challenge-Brochure-Translation.ipynb @@ -338,7 +338,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/community-contributions/day1-selenium-for-javascript-sites.ipynb b/week1/community-contributions/day1-selenium-for-javascript-sites.ipynb index 6d5ec07..fd3a3ba 100644 --- a/week1/community-contributions/day1-selenium-for-javascript-sites.ipynb +++ b/week1/community-contributions/day1-selenium-for-javascript-sites.ipynb @@ -376,7 +376,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/community-contributions/day5-improved-comments-spanish.ipynb b/week1/community-contributions/day5-improved-comments-spanish.ipynb index e2009f1..f8f4114 100644 --- a/week1/community-contributions/day5-improved-comments-spanish.ipynb +++ b/week1/community-contributions/day5-improved-comments-spanish.ipynb @@ -274,7 +274,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/community-contributions/day5-stream.ipynb b/week1/community-contributions/day5-stream.ipynb new file mode 100644 index 0000000..acd577e --- /dev/null +++ b/week1/community-contributions/day5-stream.ipynb @@ -0,0 +1,625 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a98030af-fcd1-4d63-a36e-38ba053498fa", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "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", + "\n", + "See the end of this notebook for examples of real-world business applications.\n", + "\n", + "And remember: I'm always available if you have problems or ideas! Please do reach out." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5b08506-dc8b-4443-9201-5f1848161363", + "metadata": {}, + "outputs": [], + "source": [ + "# imports\n", + "# If these fail, please check you're running from an 'activated' environment with (llms) in the command prompt\n", + "\n", + "import os\n", + "import requests\n", + "import json\n", + "from typing import List\n", + "from dotenv import load_dotenv\n", + "from bs4 import BeautifulSoup\n", + "from IPython.display import Markdown, display, update_display\n", + "from openai import OpenAI\n", + "\n", + "# from Kamran; to use Llama instead of chatgpt;\n", + "# imports\n", + "\n", + "import ollama" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc5d8880-f2ee-4c06-af16-ecbc0262af61", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# Initialize and constants\n", + "\n", + "# Commented out belwo lines;\n", + "# load_dotenv()\n", + "# api_key = os.getenv('OPENAI_API_KEY')\n", + "\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", + " \n", + "# MODEL = 'gpt-4o-mini'\n", + "# openai = OpenAI()\n", + "\n", + "# Added by Kamran.\n", + "MODEL_LLAMA = 'llama3.2'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "106dd65e-90af-4ca8-86b6-23a41840645b", + "metadata": {}, + "outputs": [], + "source": [ + "# 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", + "\n", + " def __init__(self, url):\n", + " self.url = url\n", + " response = requests.get(url)\n", + " self.body = response.content\n", + " soup = BeautifulSoup(self.body, 'html.parser')\n", + " self.title = soup.title.string if soup.title else \"No title found\"\n", + " if soup.body:\n", + " for irrelevant in soup.body([\"script\", \"style\", \"img\", \"input\"]):\n", + " irrelevant.decompose()\n", + " self.text = soup.body.get_text(separator=\"\\n\", strip=True)\n", + " else:\n", + " self.text = \"\"\n", + " links = [link.get('href') for link in soup.find_all('a')]\n", + " self.links = [link for link in links if link]\n", + "\n", + " def get_contents(self):\n", + " return f\"Webpage Title:\\n{self.title}\\nWebpage Contents:\\n{self.text}\\n\\n\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e30d8128-933b-44cc-81c8-ab4c9d86589a", + "metadata": {}, + "outputs": [], + "source": [ + "ed = Website(\"https://edwarddonner.com\")\n", + "ed.links" + ] + }, + { + "cell_type": "markdown", + "id": "1771af9c-717a-4fca-bbbe-8a95893312c3", + "metadata": {}, + "source": [ + "## First step: Have GPT-4o-mini figure out which links are relevant\n", + "\n", + "### Use a call to gpt-4o-mini to read the links on a webpage, and respond in structured JSON. \n", + "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." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6957b079-0d96-45f7-a26a-3487510e9b35", + "metadata": {}, + "outputs": [], + "source": [ + "link_system_prompt = \"You are provided with a list of links found on a webpage. \\\n", + "You are able to decide which of the links would be most relevant to include in a brochure about the company, \\\n", + "such as links to an About page, or a Company page, or Careers/Jobs pages.\\n\"\n", + "link_system_prompt += \"You should respond in JSON as in this example:\"\n", + "link_system_prompt += \"\"\"\n", + "{\n", + " \"links\": [\n", + " {\"type\": \"about page\", \"url\": \"https://full.url/goes/here/about\"},\n", + " {\"type\": \"careers page\": \"url\": \"https://another.full.url/careers\"}\n", + " ]\n", + "}\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b97e4068-97ed-4120-beae-c42105e4d59a", + "metadata": {}, + "outputs": [], + "source": [ + "print(link_system_prompt)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e1f601b-2eaf-499d-b6b8-c99050c9d6b3", + "metadata": {}, + "outputs": [], + "source": [ + "def get_links_user_prompt(website):\n", + " user_prompt = f\"Here is the list of links on the website of {website.url} - \"\n", + " user_prompt += \"please decide which of these are relevant web links for a brochure about the company, respond with the full https URL in JSON format. \\\n", + "Do not include Terms of Service, Privacy, email links.\\n\"\n", + " user_prompt += \"Links (some might be relative links):\\n\"\n", + " user_prompt += \"\\n\".join(website.links)\n", + " return user_prompt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6bcbfa78-6395-4685-b92c-22d592050fd7", + "metadata": {}, + "outputs": [], + "source": [ + "print(get_links_user_prompt(ed))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a29aca19-ca13-471c-a4b4-5abbfa813f69", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# Get Llama 3.2 to answer\n", + "\n", + "# def get_links(url):\n", + "# website = Website(url)\n", + "# response = openai.chat.completions.create(\n", + "# model=MODEL,\n", + "# messages=[\n", + "# {\"role\": \"system\", \"content\": link_system_prompt},\n", + "# {\"role\": \"user\", \"content\": get_links_user_prompt(website)}\n", + "# ],\n", + "# response_format={\"type\": \"json_object\"}\n", + "# )\n", + "# result = response.choices[0].message.content\n", + "# return json.loads(result)\n", + "\n", + "def get_links(url):\n", + " website = Website(url)\n", + " response = ollama.chat(\n", + " model=MODEL_LLAMA,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": link_system_prompt},\n", + " {\"role\": \"user\", \"content\": get_links_user_prompt(website)}\n", + " ]\n", + " )\n", + " result = response['message']['content']\n", + " print(f\"About to parse this into json: {result}\")\n", + " return json.loads(result)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74a827a0-2782-4ae5-b210-4a242a8b4cc2", + "metadata": {}, + "outputs": [], + "source": [ + "anthropic = Website(\"https://anthropic.com\")\n", + "anthropic.links" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3d583e2-dcc4-40cc-9b28-1e8dbf402924", + "metadata": {}, + "outputs": [], + "source": [ + "get_links(\"https://anthropic.com\")" + ] + }, + { + "cell_type": "markdown", + "id": "0d74128e-dfb6-47ec-9549-288b621c838c", + "metadata": {}, + "source": [ + "## Second step: make the brochure!\n", + "\n", + "Assemble all the details into another prompt to GPT4-o" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85a5b6e2-e7ef-44a9-bc7f-59ede71037b5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_all_details(url):\n", + " result = \"Landing page:\\n\"\n", + " result += Website(url).get_contents()\n", + " links = get_links(url)\n", + " print(\"Found links:\", links)\n", + " for link in links[\"links\"]:\n", + " result += f\"\\n\\n{link['type']}\\n\"\n", + " result += Website(link[\"url\"]).get_contents()\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5099bd14-076d-4745-baf3-dac08d8e5ab2", + "metadata": {}, + "outputs": [], + "source": [ + "print(get_all_details(\"https://anthropic.com\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b863a55-f86c-4e3f-8a79-94e24c1a8cf2", + "metadata": {}, + "outputs": [], + "source": [ + "system_prompt = \"You are an assistant that analyzes the contents of several relevant pages from a company website \\\n", + "and creates a short brochure about the company for prospective customers, investors and recruits. Respond in markdown.\\\n", + "Include details of company culture, customers and careers/jobs if you have the information.\"\n", + "\n", + "# Or uncomment the lines below for a more humorous brochure - this demonstrates how easy it is to incorporate 'tone':\n", + "\n", + "# system_prompt = \"You are an assistant that analyzes the contents of several relevant pages from a company website \\\n", + "# and creates a short humorous, entertaining, jokey brochure about the company for prospective customers, investors and recruits. Respond in markdown.\\\n", + "# Include details of company culture, customers and careers/jobs if you have the information.\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ab83d92-d36b-4ce0-8bcc-5bb4c2f8ff23", + "metadata": {}, + "outputs": [], + "source": [ + "def get_brochure_user_prompt(company_name, url):\n", + " user_prompt = f\"You are looking at a company called: {company_name}\\n\"\n", + " user_prompt += f\"Here are the contents of its landing page and other relevant pages; use this information to build a short brochure of the company in markdown.\\n\"\n", + " user_prompt += get_all_details(url)\n", + " user_prompt = user_prompt[:20_000] # Truncate if more than 20,000 characters\n", + " return user_prompt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd909e0b-1312-4ce2-a553-821e795d7572", + "metadata": {}, + "outputs": [], + "source": [ + "get_brochure_user_prompt(\"Anthropic\", \"https://anthropic.com\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e44de579-4a1a-4e6a-a510-20ea3e4b8d46", + "metadata": {}, + "outputs": [], + "source": [ + "# def create_brochure(company_name, url):\n", + "# response = openai.chat.completions.create(\n", + "# model=MODEL,\n", + "# messages=[\n", + "# {\"role\": \"system\", \"content\": system_prompt},\n", + "# {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name, url)}\n", + "# ],\n", + "# )\n", + "# result = response.choices[0].message.content\n", + "# display(Markdown(result))\n", + "\n", + "def create_brochure(company_name, url):\n", + " response = ollama.chat(\n", + " model=MODEL_LLAMA,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": system_prompt},\n", + " {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name, url)}\n", + " ]\n", + " )\n", + " result = response['message']['content']\n", + " display(Markdown(result))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e093444a-9407-42ae-924a-145730591a39", + "metadata": {}, + "outputs": [], + "source": [ + "create_brochure(\"Anthropic\", \"https://anthropic.com\")" + ] + }, + { + "cell_type": "markdown", + "id": "61eaaab7-0b47-4b29-82d4-75d474ad8d18", + "metadata": {}, + "source": [ + "## Finally - a minor improvement\n", + "\n", + "With a small adjustment, we can change this so that the results stream back from OpenAI,\n", + "with the familiar typewriter animation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51db0e49-f261-4137-aabe-92dd601f7725", + "metadata": {}, + "outputs": [], + "source": [ + "# def stream_brochure(company_name, url):\n", + "# stream = openai.chat.completions.create(\n", + "# model=MODEL,\n", + "# messages=[\n", + "# {\"role\": \"system\", \"content\": system_prompt},\n", + "# {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name, url)}\n", + "# ],\n", + "# stream=True\n", + "# )\n", + "\n", + "# # For just a simple output you can do the following two lines;\n", + "# # for chunk in stream:\n", + "# # print(chunk.choices[0].delta.content or '',end='')\n", + " \n", + "# response = \"\"\n", + "# display_handle = display(Markdown(\"\"), display_id=True)\n", + "# for chunk in stream:\n", + "# response += chunk.choices[0].delta.content or ''\n", + "# response = response.replace(\"```\",\"\").replace(\"markdown\", \"\")\n", + "# update_display(Markdown(response), display_id=display_handle.display_id)\n", + "\n", + "def stream_brochure(company_name, url):\n", + " stream = ollama.chat(\n", + " model=MODEL_LLAMA,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": system_prompt},\n", + " {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name, url)}\n", + " ],\n", + " stream=True\n", + " )\n", + "\n", + " # For just a simple output you can do the following two lines;\n", + " # for chunk in stream:\n", + " # print(chunk['message']['content'] or '', end='')\n", + "\n", + " response = \"\"\n", + " display_handle = display(Markdown(\"\"), display_id=True)\n", + " for chunk in stream:\n", + " response += chunk['message']['content'] or ''\n", + " response = response.replace(\"```\", \"\").replace(\"markdown\", \"\")\n", + " update_display(Markdown(response), display_id=display_handle.display_id)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56bf0ae3-ee9d-4a72-9cd6-edcac67ceb6d", + "metadata": {}, + "outputs": [], + "source": [ + "stream_brochure(\"Anthropic\", \"https://anthropic.com\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdb3f8d8-a3eb-41c8-b1aa-9f60686a653b", + "metadata": {}, + "outputs": [], + "source": [ + "# Try changing the system prompt to the humorous version when you make the Brochure for Hugging Face:\n", + "\n", + "stream_brochure(\"HuggingFace\", \"https://huggingface.co\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5567d103-74ee-4a7a-997c-eaf2c3baf7f4", + "metadata": {}, + "outputs": [], + "source": [ + "def test_llama_response_basic(company_name, url):\n", + " try:\n", + " response = ollama.chat(\n", + " model=MODEL_LLAMA,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": system_prompt},\n", + " {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name, url)}\n", + " ]\n", + " )\n", + "\n", + " # Print the entire raw response for debugging purposes\n", + " print(\"Raw response received:\", response)\n", + "\n", + " # Check if the response contains 'message' and 'content'\n", + " if 'message' in response and 'content' in response['message']:\n", + " response_content = response['message']['content']\n", + " print(\"Content from response:\", response_content)\n", + " return response_content\n", + " else:\n", + " print(\"Response does not contain expected 'message' or 'content'\")\n", + " return response\n", + "\n", + " except Exception as e:\n", + " print(f\"An error occurred: {e}\")\n", + " return {}\n", + "\n", + "# Example usage\n", + "test_llama_response_basic(\"HuggingFace\", \"https://huggingface.co\")\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "a27bf9e0-665f-4645-b66b-9725e2a959b5", + "metadata": {}, + "source": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + "

Business applications

\n", + " In this exercise we extended the Day 1 code to make multiple LLM calls, and generate a document.\n", + "\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", + "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.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "14b2454b-8ef8-4b5c-b928-053a15e0d553", + "metadata": {}, + "source": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + "

Before you move to Week 2 (which is tons of fun)

\n", + " 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.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "17b64f0f-7d33-4493-985a-033d06e8db08", + "metadata": {}, + "source": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + "

A reminder on 2 useful resources

\n", + " 1. The resources for the course are available here.
\n", + " 2. I'm on LinkedIn here and I love connecting with people taking the course!\n", + "
\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8fbce9d-51e5-4e8c-a7a9-c88ad02fffdf", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "from dotenv import load_dotenv\n", + "\n", + "load_dotenv()\n", + "hf_token=os.getenv(\"HF_TOKEN\")\n", + "print(f\"Using this HF Token: {hf_token}\")\n", + "\n", + "API_URL = \"https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B\"\n", + "headers = {\"Authorization\": f\"Bearer {hf_token}\"}\n", + "\n", + "def query(payload):\n", + "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n", + "\treturn response.json()\n", + "\t\n", + "output = query({\n", + "\t\"inputs\": \"2 + 2 is \",\n", + "})\n", + "print(output)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec2b37af-566e-4b0b-ad4a-8b46cc346e46", + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/week1/day1.ipynb b/week1/day1.ipynb index 4688043..2c2e1c2 100644 --- a/week1/day1.ipynb +++ b/week1/day1.ipynb @@ -144,6 +144,36 @@ "# openai = OpenAI(api_key=\"your-key-here-starting-sk-proj-\")" ] }, + { + "cell_type": "markdown", + "id": "442fc84b-0815-4f40-99ab-d9a5da6bda91", + "metadata": {}, + "source": [ + "# Let's make a quick call to a Frontier model to get started, as a preview!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a58394bf-1e45-46af-9bfd-01e24da6f49a", + "metadata": {}, + "outputs": [], + "source": [ + "# To give you a preview -- calling OpenAI with these messages is this easy:\n", + "\n", + "message = \"Hello, GPT! This is my first ever message to you! Hi!\"\n", + "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=[{\"role\":\"user\", \"content\":message}])\n", + "print(response.choices[0].message.content)" + ] + }, + { + "cell_type": "markdown", + "id": "2aa190e5-cb31-456a-96cc-db109919cd78", + "metadata": {}, + "source": [ + "## OK onwards with our first project" + ] + }, { "cell_type": "code", "execution_count": null, @@ -257,9 +287,45 @@ "[\n", " {\"role\": \"system\", \"content\": \"system message goes here\"},\n", " {\"role\": \"user\", \"content\": \"user message goes here\"}\n", + "]\n", + "\n", + "To give you a preview, the next 2 cells make a rather simple call - we won't stretch the might GPT (yet!)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f25dcd35-0cd0-4235-9f64-ac37ed9eaaa5", + "metadata": {}, + "outputs": [], + "source": [ + "messages = [\n", + " {\"role\": \"system\", \"content\": \"You are a snarky assistant\"},\n", + " {\"role\": \"user\", \"content\": \"What is 2 + 2?\"}\n", "]" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "21ed95c5-7001-47de-a36d-1d6673b403ce", + "metadata": {}, + "outputs": [], + "source": [ + "# To give you a preview -- calling OpenAI with system and user messages:\n", + "\n", + "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", + "print(response.choices[0].message.content)" + ] + }, + { + "cell_type": "markdown", + "id": "d06e8d78-ce4c-4b05-aa8e-17050c82bb47", + "metadata": {}, + "source": [ + "## And now let's build useful messages for GPT-4o-mini, using a function" + ] + }, { "cell_type": "code", "execution_count": null, @@ -493,7 +559,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/day2 EXERCISE.ipynb b/week1/day2 EXERCISE.ipynb index 6bdbde5..4504401 100644 --- a/week1/day2 EXERCISE.ipynb +++ b/week1/day2 EXERCISE.ipynb @@ -158,6 +158,35 @@ "print(response['message']['content'])" ] }, + { + "cell_type": "markdown", + "id": "a4704e10-f5fb-4c15-a935-f046c06fb13d", + "metadata": {}, + "source": [ + "## Alternative approach - using OpenAI python library to connect to Ollama" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23057e00-b6fc-4678-93a9-6b31cb704bff", + "metadata": {}, + "outputs": [], + "source": [ + "# There's actually an alternative approach that some people might prefer\n", + "# You can use the OpenAI client python library to call Ollama:\n", + "\n", + "from openai import OpenAI\n", + "ollama_via_openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n", + "\n", + "response = ollama_via_openai.chat.completions.create(\n", + " model=MODEL,\n", + " messages=messages\n", + ")\n", + "\n", + "print(response.choices[0].message.content)" + ] + }, { "cell_type": "markdown", "id": "1622d9bb-5c68-4d4e-9ca4-b492c751f898", @@ -165,8 +194,16 @@ "source": [ "# NOW the exercise for you\n", "\n", - "Take the code from day1 and incorporate it here, to build a website summarizer that uses Llama 3.2 running locally instead of OpenAI" + "Take the code from day1 and incorporate it here, to build a website summarizer that uses Llama 3.2 running locally instead of OpenAI; use either of the above approaches." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "402d5686-4e76-4110-b65a-b3906c35c0a4", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -185,7 +222,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/day5.ipynb b/week1/day5.ipynb index 037e278..3cdc54a 100644 --- a/week1/day5.ipynb +++ b/week1/day5.ipynb @@ -206,8 +206,10 @@ "metadata": {}, "outputs": [], "source": [ - "anthropic = Website(\"https://anthropic.com\")\n", - "anthropic.links" + "# Anthropic has made their site harder to scrape, so I'm using HuggingFace..\n", + "\n", + "huggingface = Website(\"https://huggingface.co\")\n", + "huggingface.links" ] }, { @@ -217,7 +219,7 @@ "metadata": {}, "outputs": [], "source": [ - "get_links(\"https://anthropic.com\")" + "get_links(\"https://huggingface.co\")" ] }, { @@ -255,7 +257,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(get_all_details(\"https://anthropic.com\"))" + "print(get_all_details(\"https://huggingface.co\"))" ] }, { @@ -287,7 +289,7 @@ " user_prompt = f\"You are looking at a company called: {company_name}\\n\"\n", " user_prompt += f\"Here are the contents of its landing page and other relevant pages; use this information to build a short brochure of the company in markdown.\\n\"\n", " user_prompt += get_all_details(url)\n", - " user_prompt = user_prompt[:20_000] # Truncate if more than 20,000 characters\n", + " user_prompt = user_prompt[:5_000] # Truncate if more than 5,000 characters\n", " return user_prompt" ] }, @@ -298,7 +300,7 @@ "metadata": {}, "outputs": [], "source": [ - "get_brochure_user_prompt(\"Anthropic\", \"https://anthropic.com\")" + "get_brochure_user_prompt(\"HuggingFace\", \"https://huggingface.co\")" ] }, { @@ -327,7 +329,7 @@ "metadata": {}, "outputs": [], "source": [ - "create_brochure(\"Anthropic\", \"https://anthropic.com\")" + "create_brochure(\"HuggingFace\", \"https://huggingface.com\")" ] }, { @@ -373,7 +375,7 @@ "metadata": {}, "outputs": [], "source": [ - "stream_brochure(\"Anthropic\", \"https://anthropic.com\")" + "stream_brochure(\"HuggingFace\", \"https://huggingface.co\")" ] }, { @@ -473,7 +475,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/troubleshooting.ipynb b/week1/troubleshooting.ipynb index 1b1e45f..3811bbb 100644 --- a/week1/troubleshooting.ipynb +++ b/week1/troubleshooting.ipynb @@ -331,6 +331,22 @@ "from diagnostics import Diagnostics\n", "Diagnostics().run()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7cd162d4-ebde-4a39-a9b0-bee3633907cb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b053b313-7ccc-4aff-a562-2479eb890918", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -349,7 +365,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week1/week1 EXERCISE.ipynb b/week1/week1 EXERCISE.ipynb index 3b74f8d..f3486fe 100644 --- a/week1/week1 EXERCISE.ipynb +++ b/week1/week1 EXERCISE.ipynb @@ -96,7 +96,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb b/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb index ccd8a6e..4de21e4 100644 --- a/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb +++ b/week2/community-contributions/Week2_Day2_AddGeminModel.ipynb @@ -572,7 +572,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/day1-azure-aws-ollama.ipynb b/week2/community-contributions/day1-azure-aws-ollama.ipynb index dfb346b..304b38c 100644 --- a/week2/community-contributions/day1-azure-aws-ollama.ipynb +++ b/week2/community-contributions/day1-azure-aws-ollama.ipynb @@ -22,7 +22,7 @@ "\n", " \n", " \n", "
\n", - " \n", + " \n", " \n", "

Important Note - Please read me

\n", @@ -41,7 +41,7 @@ "\n", " \n", " \n", "
\n", - " \n", + " \n", " \n", "

Reminder about the resources page

\n", @@ -610,7 +610,7 @@ "\n", " \n", " \n", "
\n", - " \n", + " \n", " \n", "

Before you continue

\n", @@ -646,7 +646,7 @@ "\n", " \n", " \n", "
\n", - " \n", + " \n", " \n", "

Business relevance

\n", @@ -667,7 +667,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -681,7 +681,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/day1-with-3way.ipynb b/week2/community-contributions/day1-with-3way.ipynb index 5681e64..2cf96ba 100644 --- a/week2/community-contributions/day1-with-3way.ipynb +++ b/week2/community-contributions/day1-with-3way.ipynb @@ -641,7 +641,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/day2.ipynb b/week2/community-contributions/day2.ipynb index f39ffae..05d02bf 100644 --- a/week2/community-contributions/day2.ipynb +++ b/week2/community-contributions/day2.ipynb @@ -466,7 +466,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/day4.ipynb b/week2/community-contributions/day4.ipynb index f1ef198..9c51459 100644 --- a/week2/community-contributions/day4.ipynb +++ b/week2/community-contributions/day4.ipynb @@ -292,7 +292,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/community-contributions/task1.ipynb b/week2/community-contributions/task1.ipynb index 9ca08a3..2758f89 100644 --- a/week2/community-contributions/task1.ipynb +++ b/week2/community-contributions/task1.ipynb @@ -315,7 +315,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/day1.ipynb b/week2/day1.ipynb index dda6516..fe515bc 100644 --- a/week2/day1.ipynb +++ b/week2/day1.ipynb @@ -104,8 +104,8 @@ "outputs": [], "source": [ "# import for google\n", - "# in rare cases, this seems to give an error on some systems. Please reach out to me if this happens,\n", - "# or you can feel free to skip Gemini - it's the lowest priority of the frontier models that we use\n", + "# in rare cases, this seems to give an error on some systems, or even crashes the kernel\n", + "# If this happens to you, simply ignore this cell - I give an alternative approach for using Gemini later\n", "\n", "import google.generativeai" ] @@ -148,14 +148,22 @@ "metadata": {}, "outputs": [], "source": [ - "# Connect to OpenAI, Anthropic and Google\n", - "# All 3 APIs are similar\n", - "# Having problems with API files? You can use openai = OpenAI(api_key=\"your-key-here\") and same for claude\n", - "# Having problems with Google Gemini setup? Then just skip Gemini; you'll get all the experience you need from GPT and Claude.\n", + "# Connect to OpenAI, Anthropic\n", "\n", "openai = OpenAI()\n", "\n", - "claude = anthropic.Anthropic()\n", + "claude = anthropic.Anthropic()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "425ed580-808d-429b-85b0-6cba50ca1d0c", + "metadata": {}, + "outputs": [], + "source": [ + "# This is the set up code for Gemini\n", + "# Having problems with Google Gemini setup? Then just ignore this cell; when we use Gemini, I'll give you an alternative that bypasses this library altogether\n", "\n", "google.generativeai.configure()" ] @@ -308,7 +316,9 @@ "metadata": {}, "outputs": [], "source": [ - "# The API for Gemini has a slightly different structure\n", + "# The API for Gemini has a slightly different structure.\n", + "# I've heard that on some PCs, this Gemini code causes the Kernel to crash.\n", + "# If that happens to you, please skip this cell and use the next cell instead - an alternative approach.\n", "\n", "gemini = google.generativeai.GenerativeModel(\n", " model_name='gemini-1.5-flash',\n", @@ -318,6 +328,28 @@ "print(response.text)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "49009a30-037d-41c8-b874-127f61c4aa3a", + "metadata": {}, + "outputs": [], + "source": [ + "# As an alternative way to use Gemini that bypasses Google's python API library,\n", + "# Google has recently released new endpoints that means you can use Gemini via the client libraries for OpenAI!\n", + "\n", + "gemini_via_openai_client = OpenAI(\n", + " api_key=google_api_key, \n", + " base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n", + ")\n", + "\n", + "response = gemini_via_openai_client.chat.completions.create(\n", + " model=\"gemini-1.5-flash\",\n", + " messages=prompts\n", + ")\n", + "print(response.choices[0].message.content)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -534,7 +566,7 @@ "\n", "Try creating a 3-way, perhaps bringing Gemini into the conversation! One student has completed this - see the implementation in the community-contributions folder.\n", "\n", - "Try doing this yourself before you look at the solutions.\n", + "Try doing this yourself before you look at the solutions. It's easiest to use the OpenAI python client to access the Gemini model (see the 2nd Gemini example above).\n", "\n", "## Additional exercise\n", "\n", @@ -584,7 +616,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/day2.ipynb b/week2/day2.ipynb index 4c63192..bf5367f 100644 --- a/week2/day2.ipynb +++ b/week2/day2.ipynb @@ -186,6 +186,7 @@ "source": [ "# Adding share=True means that it can be accessed publically\n", "# A more permanent hosting is available using a platform called Spaces from HuggingFace, which we will touch on next week\n", + "# NOTE: Some Anti-virus software and Corporate Firewalls might not like you using share=True. If you're at work on on a work network, I suggest skip this test.\n", "\n", "gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\", flagging_mode=\"never\").launch(share=True)" ] @@ -565,7 +566,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/day3.ipynb b/week2/day3.ipynb index 2be75a4..e9d0348 100644 --- a/week2/day3.ipynb +++ b/week2/day3.ipynb @@ -296,7 +296,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/day4.ipynb b/week2/day4.ipynb index 06c3904..811d116 100644 --- a/week2/day4.ipynb +++ b/week2/day4.ipynb @@ -44,7 +44,12 @@ " print(\"OpenAI API Key not set\")\n", " \n", "MODEL = \"gpt-4o-mini\"\n", - "openai = OpenAI()" + "openai = OpenAI()\n", + "\n", + "# As an alternative, if you'd like to use Ollama instead of OpenAI\n", + "# Check that Ollama is running for you locally (see week1/day2 exercise) then uncomment these next 2 lines\n", + "# MODEL = \"llama3.2\"\n", + "# openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n" ] }, { @@ -249,7 +254,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/day5.ipynb b/week2/day5.ipynb index 22124b3..3453ccb 100644 --- a/week2/day5.ipynb +++ b/week2/day5.ipynb @@ -296,7 +296,7 @@ "id": "f4975b87-19e9-4ade-a232-9b809ec75c9a", "metadata": {}, "source": [ - "## Audio\n", + "## Audio (NOTE - Audio is optional for this course - feel free to skip Audio if it causes trouble!)\n", "\n", "And let's make a function talker that uses OpenAI's speech model to generate Audio\n", "\n", @@ -410,12 +410,14 @@ "source": [ "# For Windows users\n", "\n", - "## if you get a permissions error writing to a temp file, then this code should work instead.\n", + "## First try the Mac version above, but if you get a permissions error writing to a temp file, then this code should work instead.\n", "\n", "A collaboration between students Mark M. and Patrick H. and Claude got this resolved!\n", "\n", "Below are 3 variations - hopefully one of them will work on your PC. If not, message me please!\n", "\n", + "And for Mac people - all 3 of the below work on my Mac too - please try these if the Mac version gave you problems.\n", + "\n", "## PC Variation 1" ] }, @@ -695,7 +697,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week2/week2 EXERCISE.ipynb b/week2/week2 EXERCISE.ipynb index 99d83cb..d97f5cb 100644 --- a/week2/week2 EXERCISE.ipynb +++ b/week2/week2 EXERCISE.ipynb @@ -43,7 +43,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day1.ipynb b/week3/day1.ipynb index b1bea54..2d76b3d 100644 --- a/week3/day1.ipynb +++ b/week3/day1.ipynb @@ -41,7 +41,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day2.ipynb b/week3/day2.ipynb index 9c4e01f..eab737e 100644 --- a/week3/day2.ipynb +++ b/week3/day2.ipynb @@ -41,7 +41,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day3.ipynb b/week3/day3.ipynb index 535f3ac..03c847e 100644 --- a/week3/day3.ipynb +++ b/week3/day3.ipynb @@ -37,7 +37,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day4.ipynb b/week3/day4.ipynb index 3cbd556..13aac73 100644 --- a/week3/day4.ipynb +++ b/week3/day4.ipynb @@ -31,7 +31,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day5.ipynb b/week3/day5.ipynb index 70690f7..d068f79 100644 --- a/week3/day5.ipynb +++ b/week3/day5.ipynb @@ -43,7 +43,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week4/day3.ipynb b/week4/day3.ipynb index 481e869..69188c4 100644 --- a/week4/day3.ipynb +++ b/week4/day3.ipynb @@ -505,13 +505,13 @@ "outputs": [], "source": [ "def execute_python(code):\n", - " try:\n", - " output = io.StringIO()\n", - " sys.stdout = output\n", - " exec(code)\n", - " finally:\n", - " sys.stdout = sys.__stdout__\n", - " return output.getvalue()" + " try:\n", + " output = io.StringIO()\n", + " sys.stdout = output\n", + " exec(code)\n", + " finally:\n", + " sys.stdout = sys.__stdout__\n", + " return output.getvalue()" ] }, { @@ -581,14 +581,6 @@ "\n", "ui.launch(inbrowser=True)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "77a80857-4632-4de8-a28f-b614bcbe2f40", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -607,7 +599,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week4/day4.ipynb b/week4/day4.ipynb index ea195fa..722a233 100644 --- a/week4/day4.ipynb +++ b/week4/day4.ipynb @@ -696,7 +696,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week4/optimized b/week4/optimized index 526d5b077fc636c9952d19798167035b0b609a1b..c7745a1ecb8b3aca5de64ddae6d57a4b2d680165 100755 G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generate random numbers using Mersenne Twister -std::mt19937 gen(42); +using namespace std; +using namespace chrono; + +class LCG { +private: + uint64_t value; + static const uint64_t a = 1664525; + static const uint64_t c = 1013904223; + static const uint64_t m = 1ULL << 32; + +public: + LCG(uint64_t seed) : value(seed) {} + + uint64_t next() { + value = (a * value + c) % m; + return value; + } +}; + +int64_t max_subarray_sum(int n, uint64_t seed, int min_val, int max_val) { + LCG lcg(seed); + vector random_numbers(n); + for (int i = 0; i < n; ++i) { + random_numbers[i] = lcg.next() % (max_val - min_val + 1) + min_val; + } + + int64_t max_sum = numeric_limits::min(); + int64_t current_sum = 0; + int64_t min_sum = 0; -// Function to calculate maximum subarray sum -int max_subarray_sum(int n, int min_val, int max_val) { - std::uniform_int_distribution<> dis(min_val, max_val); - int max_sum = std::numeric_limits::min(); - int current_sum = 0; for (int i = 0; i < n; ++i) { - current_sum += dis(gen); - if (current_sum > max_sum) { - max_sum = current_sum; - } - if (current_sum < 0) { - current_sum = 0; - } + current_sum += random_numbers[i]; + max_sum = max(max_sum, current_sum - min_sum); + min_sum = min(min_sum, current_sum); } + return max_sum; } -// Function to calculate total maximum subarray sum -int total_max_subarray_sum(int n, int initial_seed, int min_val, int max_val) { - gen.seed(initial_seed); - int total_sum = 0; +int64_t total_max_subarray_sum(int n, uint64_t initial_seed, int min_val, int max_val) { + int64_t total_sum = 0; + LCG lcg(initial_seed); for (int i = 0; i < 20; ++i) { - total_sum += max_subarray_sum(n, min_val, max_val); + uint64_t seed = lcg.next(); + total_sum += max_subarray_sum(n, seed, min_val, max_val); } return total_sum; } int main() { - int n = 10000; // Number of random numbers - int initial_seed = 42; // Initial seed for the Mersenne Twister - int min_val = -10; // Minimum value of random numbers - int max_val = 10; // Maximum value of random numbers - - // Timing the function - auto start_time = std::chrono::high_resolution_clock::now(); - int result = total_max_subarray_sum(n, initial_seed, min_val, max_val); - auto end_time = std::chrono::high_resolution_clock::now(); - - std::cout << "Total Maximum Subarray Sum (20 runs): " << result << std::endl; - std::cout << "Execution Time: " << std::setprecision(6) << std::fixed << std::chrono::duration(end_time - start_time).count() << " seconds" << std::endl; + const int n = 10000; + const uint64_t initial_seed = 42; + const int min_val = -10; + const int max_val = 10; + + auto start_time = high_resolution_clock::now(); + int64_t result = total_max_subarray_sum(n, initial_seed, min_val, max_val); + auto end_time = high_resolution_clock::now(); + + auto duration = duration_cast(end_time - start_time); + + cout << "Total Maximum Subarray Sum (20 runs): " << result << endl; + cout << "Execution Time: " << fixed << setprecision(6) << duration.count() / 1e6 << " seconds" << endl; return 0; } \ No newline at end of file diff --git a/week5/community-contributions/day3 - extended for Obsidian files and separate ingestion.ipynb b/week5/community-contributions/day3 - extended for Obsidian files and separate ingestion.ipynb index 2230c68..161eb8d 100644 --- a/week5/community-contributions/day3 - extended for Obsidian files and separate ingestion.ipynb +++ b/week5/community-contributions/day3 - extended for Obsidian files and separate ingestion.ipynb @@ -388,7 +388,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/community-contributions/day4 - taking advantage of separate ingestion.ipynb b/week5/community-contributions/day4 - taking advantage of separate ingestion.ipynb index 188bc8a..bb16478 100644 --- a/week5/community-contributions/day4 - taking advantage of separate ingestion.ipynb +++ b/week5/community-contributions/day4 - taking advantage of separate ingestion.ipynb @@ -421,7 +421,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day1.ipynb b/week5/day1.ipynb index 1ccdd33..f4bc48e 100644 --- a/week5/day1.ipynb +++ b/week5/day1.ipynb @@ -256,7 +256,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day2.ipynb b/week5/day2.ipynb index 824c75b..8c19368 100644 --- a/week5/day2.ipynb +++ b/week5/day2.ipynb @@ -169,14 +169,6 @@ " print(chunk)\n", " print(\"_________\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6965971c-fb97-482c-a497-4e81a0ac83df", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -195,7 +187,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day3.ipynb b/week5/day3.ipynb index a092bbb..764f13c 100644 --- a/week5/day3.ipynb +++ b/week5/day3.ipynb @@ -352,7 +352,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day4.5.ipynb b/week5/day4.5.ipynb index 13de8d7..a02b9cd 100644 --- a/week5/day4.5.ipynb +++ b/week5/day4.5.ipynb @@ -214,7 +214,9 @@ "source": [ "## Visualizing the Vector Store\n", "\n", - "Let's take a minute to look at the documents and their embedding vectors to see what's going on." + "Let's take a minute to look at the documents and their embedding vectors to see what's going on.\n", + "\n", + "(As a sidenote, what we're really looking at here is the distribution of the Vectors generated by OpenAIEmbeddings, retrieved from FAISS. So there's no surprise that they look the same whether they are \"from\" FAISS or Chroma.)" ] }, { @@ -326,6 +328,17 @@ "print(result[\"answer\"])" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "987dadc5-5d09-4059-8f2e-733d66ecc696", + "metadata": {}, + "outputs": [], + "source": [ + "memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)\n", + "conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory)" + ] + }, { "cell_type": "markdown", "id": "bbbcb659-13ce-47ab-8a5e-01b930494964", @@ -387,7 +400,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day4.ipynb b/week5/day4.ipynb index d3d1ad0..43aa358 100644 --- a/week5/day4.ipynb +++ b/week5/day4.ipynb @@ -404,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week5/day5.ipynb b/week5/day5.ipynb index 141b518..5c29d40 100644 --- a/week5/day5.ipynb +++ b/week5/day5.ipynb @@ -50,7 +50,8 @@ "import numpy as np\n", "import plotly.graph_objects as go\n", "from langchain.memory import ConversationBufferMemory\n", - "from langchain.chains import ConversationalRetrievalChain" + "from langchain.chains import ConversationalRetrievalChain\n", + "from langchain.embeddings import HuggingFaceEmbeddings" ] }, { @@ -147,6 +148,10 @@ "\n", "embeddings = OpenAIEmbeddings()\n", "\n", + "# If you would rather use the free Vector Embeddings from HuggingFace sentence-transformers\n", + "# Then uncomment this line instead\n", + "# embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")\n", + "\n", "# Delete if already exists\n", "\n", "if os.path.exists(db_name):\n", @@ -289,6 +294,9 @@ "# create a new Chat with OpenAI\n", "llm = ChatOpenAI(temperature=0.7, model_name=MODEL)\n", "\n", + "# Alternative - if you'd like to use Ollama locally, uncomment this line instead\n", + "# llm = ChatOpenAI(temperature=0.7, model_name='llama3.2', base_url='http://localhost:11434/v1', api_key='ollama')\n", + "\n", "# set up the conversation memory for the chat\n", "memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)\n", "\n", @@ -427,7 +435,7 @@ "metadata": {}, "outputs": [], "source": [ - "view = gr.ChatInterface(chat).launch()" + "view = gr.ChatInterface(chat, type=\"messages\").launch(inbrowser=True)" ] }, { @@ -465,7 +473,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week6/day1.ipynb b/week6/day1.ipynb index 0d50223..c424656 100644 --- a/week6/day1.ipynb +++ b/week6/day1.ipynb @@ -419,7 +419,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/agents/messaging_agent.py b/week8/agents/messaging_agent.py index 70e74d0..7494703 100644 --- a/week8/agents/messaging_agent.py +++ b/week8/agents/messaging_agent.py @@ -1,10 +1,11 @@ import os -from twilio.rest import Client +# from twilio.rest import Client from agents.deals import Opportunity import http.client import urllib from agents.agent import Agent +# Uncomment the Twilio lines if you wish to use Twilio DO_TEXT = False DO_PUSH = True @@ -26,7 +27,7 @@ class MessagingAgent(Agent): auth_token = os.getenv('TWILIO_AUTH_TOKEN', 'your-auth-if-not-using-env') self.me_from = os.getenv('TWILIO_FROM', 'your-phone-number-if-not-using-env') self.me_to = os.getenv('MY_PHONE_NUMBER', 'your-phone-number-if-not-using-env') - self.client = Client(account_sid, auth_token) + # self.client = Client(account_sid, auth_token) self.log("Messaging Agent has initialized Twilio") if DO_PUSH: self.pushover_user = os.getenv('PUSHOVER_USER', 'your-pushover-user-if-not-using-env') diff --git a/week8/day1.ipynb b/week8/day1.ipynb index 4e5f0ab..0836b59 100644 --- a/week8/day1.ipynb +++ b/week8/day1.ipynb @@ -317,7 +317,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day2.0.ipynb b/week8/day2.0.ipynb index d93b1f3..27424e6 100644 --- a/week8/day2.0.ipynb +++ b/week8/day2.0.ipynb @@ -264,7 +264,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day2.1.ipynb b/week8/day2.1.ipynb index 0b29b76..fac26d8 100644 --- a/week8/day2.1.ipynb +++ b/week8/day2.1.ipynb @@ -174,7 +174,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day2.2.ipynb b/week8/day2.2.ipynb index 6ef641b..f55ae2a 100644 --- a/week8/day2.2.ipynb +++ b/week8/day2.2.ipynb @@ -166,7 +166,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day2.3.ipynb b/week8/day2.3.ipynb index 5b2b970..bb9a217 100644 --- a/week8/day2.3.ipynb +++ b/week8/day2.3.ipynb @@ -391,7 +391,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day2.4.ipynb b/week8/day2.4.ipynb index 6333ae6..7d357e2 100644 --- a/week8/day2.4.ipynb +++ b/week8/day2.4.ipynb @@ -400,7 +400,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day3.ipynb b/week8/day3.ipynb index 01936d3..9effc96 100644 --- a/week8/day3.ipynb +++ b/week8/day3.ipynb @@ -227,7 +227,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day4.ipynb b/week8/day4.ipynb index 26d6132..4cd5d8f 100644 --- a/week8/day4.ipynb +++ b/week8/day4.ipynb @@ -133,7 +133,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/day5.ipynb b/week8/day5.ipynb index 400a11e..e30130d 100644 --- a/week8/day5.ipynb +++ b/week8/day5.ipynb @@ -133,12 +133,32 @@ "And now we'll move to the price_is_right.py code, followed by price_is_right_final.py" ] }, + { + "cell_type": "markdown", + "id": "d783af8a-08a8-4e59-886a-7ca32f16bcf5", + "metadata": {}, + "source": [ + "# Running the final product\n", + "\n", + "## Just hit shift + enter in the next cell, and let the deals flow in!!" + ] + }, { "cell_type": "code", "execution_count": null, "id": "48506465-1c7a-433f-a665-b277a8b4665c", "metadata": {}, "outputs": [], + "source": [ + "!python price_is_right_final.py" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d468291f-abe2-4fd7-97a6-43c714292973", + "metadata": {}, + "outputs": [], "source": [] } ], @@ -158,7 +178,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week8/memory.json b/week8/memory.json index 2fb4bd1..8705760 100644 --- a/week8/memory.json +++ b/week8/memory.json @@ -16,5 +16,23 @@ }, "estimate": 930.8824204895075, "discount": 225.88242048950747 + }, + { + "deal": { + "product_description": "The Insignia Class F30 Series NS-55F301NA25 is a 55\" 4K HDR UHD Smart TV with a native resolution of 3840x2160. Featuring HDR support, it enhances color and contrast for a more dynamic viewing experience. The TV integrates seamlessly with Amazon Fire TV, working with both Amazon Alexa and Google Home for voice control. It offers three HDMI ports for multiple device connections, making it a perfect entertainment hub for your living space.", + "price": 200.0, + "url": "https://www.dealnews.com/products/Insignia/Insignia-Class-F30-Series-NS-55-F301-NA25-55-4-K-HDR-LED-UHD-Smart-TV/467523.html?iref=rss-f1912" + }, + "estimate": 669.1921927283588, + "discount": 469.1921927283588 + }, + { + "deal": { + "product_description": "The Samsung 27-Cu. Ft. Mega Capacity 3-Door French Door Counter Depth Refrigerator combines style with spacious organization. This model features a dual auto ice maker, which ensures you always have ice on hand, and adjustable shelves that provide versatile storage options for your groceries. Designed with a sleek, fingerprint resistant finish, it not only looks modern but also simplifies cleaning. With its generous capacity, this refrigerator is perfect for large households or those who love to entertain.", + "price": 1299.0, + "url": "https://www.dealnews.com/products/Samsung/Samsung-27-Cu-Ft-Mega-Capacity-3-Door-French-Door-Counter-Depth-Refrigerator/454702.html?iref=rss-c196" + }, + "estimate": 2081.647127763905, + "discount": 782.6471277639048 } ] \ No newline at end of file