diff --git a/week1/day1.ipynb b/week1/day1.ipynb index 27684fe..693af5a 100644 --- a/week1/day1.ipynb +++ b/week1/day1.ipynb @@ -88,6 +88,16 @@ "" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab982202-e56b-4b71-989d-678853f563ff", + "metadata": {}, + "outputs": [], + "source": [ + "##Changes" + ] + }, { "cell_type": "code", "execution_count": null, @@ -186,6 +196,19 @@ "print(response.choices[0].message.content)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c0432d6-7353-4712-b753-b1d398c0ed17", + "metadata": {}, + "outputs": [], + "source": [ + "## We can change the model for this response. Any model from openai can be used here\n", + "message = \"Hello, GPT! This is my first ever message to you! Hi!\"\n", + "response = openai.chat.completions.create(model=\"gpt-4\", messages=[{\"role\":\"user\", \"content\":message}])\n", + "print(response.choices[0].message.content)" + ] + }, { "cell_type": "markdown", "id": "2aa190e5-cb31-456a-96cc-db109919cd78", @@ -233,7 +256,7 @@ "source": [ "# Let's try one out. Change the website and add print statements to follow along.\n", "\n", - "ed = Website(\"https://edwarddonner.com\")\n", + "ed = Website(\"https://fairlycurated.com\")\n", "print(ed.title)\n", "print(ed.text)" ] @@ -412,7 +435,7 @@ "metadata": {}, "outputs": [], "source": [ - "summarize(\"https://edwarddonner.com\")" + "summarize(\"https://fairlycurated.com\")" ] }, { @@ -436,7 +459,7 @@ "metadata": {}, "outputs": [], "source": [ - "display_summary(\"https://edwarddonner.com\")" + "display_summary(\"https://fairlycurated.com\")" ] }, { @@ -516,57 +539,31 @@ "source": [ "# Step 1: Create your prompts\n", "\n", - "system_prompt = \"something here\"\n", + "system_prompt = \"You are an app development expert who knows how to convert websites into apps with extracting key info from websites. Please give step by step on how the website can be converted into apps and using what tech stack and content. \"\n", "user_prompt = \"\"\"\n", - " Lots of text\n", - " Can be pasted here\n", + " Look at website https://fairlycurated.com/. Convert this into app and tell me step by step process.\n", "\"\"\"\n", "\n", "# Step 2: Make the messages list\n", "\n", - "messages = [] # fill this in\n", + "messages = [\n", + " {\"role\": \"system\", \"content\": system_prompt},\n", + " {\"role\": \"user\", \"content\": user_prompt}\n", + " ]\n", "\n", "# Step 3: Call OpenAI\n", "\n", - "response =\n", - "\n", - "# Step 4: print the result\n", - "\n", - "print(" - ] - }, - { - "cell_type": "markdown", - "id": "36ed9f14-b349-40e9-a42c-b367e77f8bda", - "metadata": {}, - "source": [ - "## An extra exercise for those who enjoy web scraping\n", - "\n", - "You may notice that if you try `display_summary(\"https://openai.com\")` - it doesn't work! That's because OpenAI has a fancy website that uses Javascript. There are many ways around this that some of you might be familiar with. For example, Selenium is a hugely popular framework that runs a browser behind the scenes, renders the page, and allows you to query it. If you have experience with Selenium, Playwright or similar, then feel free to improve the Website class to use them. In the community-contributions folder, you'll find an example Selenium solution from a student (thank you!)" - ] - }, - { - "cell_type": "markdown", - "id": "eeab24dc-5f90-4570-b542-b0585aca3eb6", - "metadata": {}, - "source": [ - "# Sharing your code\n", - "\n", - "I'd love it if you share your code afterwards so I can share it with others! You'll notice that some students have already made changes (including a Selenium implementation) which you will find in the community-contributions folder. If you'd like add your changes to that folder, submit a Pull Request with your new versions in that folder and I'll merge your changes.\n", + "response = openai.chat.completions.create(\n", + " model = \"gpt-4o-mini\",\n", + " messages = messages\n", + " )\n", "\n", - "If you're not an expert with git (and I am not!) then GPT has given some nice instructions on how to submit a Pull Request. It's a bit of an involved process, but once you've done it once it's pretty clear. As a pro-tip: it's best if you clear the outputs of your Jupyter notebooks (Edit >> Clean outputs of all cells, and then Save) for clean notebooks.\n", + "markdown_content = response.choices[0].message.content\n", "\n", - "Here are good instructions courtesy of an AI friend: \n", - "https://chatgpt.com/share/677a9cb5-c64c-8012-99e0-e06e88afd293" + "# Step 5: Display as markdown (if in Jupyter notebook)\n", + "from IPython.display import Markdown, display\n", + "display(Markdown(markdown_content))\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f4484fcf-8b39-4c3f-9674-37970ed71988", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {