From f23fd8248a8f5fb3bdd8bfaaf70d078a8ddd1d56 Mon Sep 17 00:00:00 2001 From: Cadeus14 Date: Sat, 25 Oct 2025 15:37:01 -0400 Subject: [PATCH] Add carl-grp's homework for week1 day2 (cleared outputs) --- .../carl-grp/week1_day2_homework.ipynb | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 community-contributions/carl-grp/week1_day2_homework.ipynb diff --git a/community-contributions/carl-grp/week1_day2_homework.ipynb b/community-contributions/carl-grp/week1_day2_homework.ipynb new file mode 100644 index 0000000..170a2f4 --- /dev/null +++ b/community-contributions/carl-grp/week1_day2_homework.ipynb @@ -0,0 +1,156 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7316c8d3", + "metadata": {}, + "source": [ + "# How well can LLMs advice on tech purchases?" + ] + }, + { + "cell_type": "markdown", + "id": "6acdeb48", + "metadata": {}, + "source": [ + "Just execute the two tries after setting everything up and take a look how both models perform in helping you choose the best new iPhone.\n", + "\n", + "I was suprised how much better ChatGPT is!\n", + "\n", + "P.S.: Since I'm German, the output and the websites are German. Just change the URLs if you want another language." + ] + }, + { + "cell_type": "markdown", + "id": "8ae52614", + "metadata": {}, + "source": [ + "### General setup" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7f15f25", + "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "import os\n", + "sys.path.append(os.path.join('..', '..', 'week1'))\n", + "from scraper import fetch_website_contents\n", + "from operator import concat\n", + "from openai import OpenAI\n", + "from IPython.display import Markdown, display\n", + "from dotenv import load_dotenv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbd7dc61", + "metadata": {}, + "outputs": [], + "source": [ + "system_prompt_homework_day2 = \"\"\"\n", + "You are tech advisor that knows about how newest mobiles like the iPhone work and what different user groups need, \n", + "like best cameras for Pro users or battery life for average consumers. \n", + "You advise fact-based and thorough on the best deals for each of your customers.\n", + "You deal with scraped websites given to you by ignoring random text from headers and footers of websites \n", + "and focusing on the content that actually presents products. \n", + "IMPORTANT: Only use facts that you got by the user via prompting.\n", + "Try hard to really identify which text is noise and which makes the product descriptions.\n", + "\"\"\"\n", + "user_prompt_prefix_homework_day2 = \"\"\"\n", + "Hi, as a student that still has the iPhone 13 Pro but wants a newer iPhone, \n", + "i need some advice on which iPhone to buy. Can you help me choose from apples website? \n", + "Here are the contents of apple's iphone websites that i obtained using a scraper.\n", + "Provide a short summary of the text from this website-scraper and afterwards help me choose the best option. \n", + "If it includes news or announcements, then summarize these too. \n", + "\"\"\"\n", + "\n", + "url_1 = \"https://www.apple.com/de/iphone-17-pro/\"\n", + "url_2 = \"https://www.apple.com/de/iphone-air/\"\n", + "url_3 = \"https://www.apple.com/de/iphone-17/\"\n", + "\n", + "urls = [url_1, url_2, url_3]\n", + "website_content_homework_day2 = \"\"\n", + "\n", + "for url in urls:\n", + " website_content_homework_day2 += fetch_website_contents(url)\n", + "\n", + "homework_day2_message = [\n", + " {\"role\":\"system\", \"content\":system_prompt_homework_day2},\n", + " {\"role\":\"user\", \"content\": user_prompt_prefix_homework_day2 + website_content_homework_day2}\n", + "]" + ] + }, + { + "cell_type": "markdown", + "id": "cc854a00", + "metadata": {}, + "source": [ + "### Try 1: Local run with Ollama 3.2 " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7fae9b5b", + "metadata": {}, + "outputs": [], + "source": [ + "!ollama pull llama3.2\n", + "\n", + "OLLAMA_BASE_URL = \"http://localhost:11434/v1\"\n", + "ollama = OpenAI(base_url=OLLAMA_BASE_URL, api_key='ollama')\n", + "\n", + "response = ollama.chat.completions.create(model=\"llama3.2\", messages=homework_day2_message,)\n", + "display(Markdown(response.choices[0].message.content))" + ] + }, + { + "cell_type": "markdown", + "id": "e7563157", + "metadata": {}, + "source": [ + "### Try 2: Online with ChatGPT-5-nano" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d764cc76", + "metadata": {}, + "outputs": [], + "source": [ + "load_dotenv(override=True)\n", + "\n", + "openai = OpenAI()\n", + "response = openai.chat.completions.create(model=\"gpt-5-nano\", messages=homework_day2_message,)\n", + "display(Markdown(response.choices[0].message.content))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "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.12.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}