3 changed files with 1901 additions and 17 deletions
@ -0,0 +1,467 @@
|
||||
{ |
||||
"cells": [ |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 10, |
||||
"id": "ac080a86-0da8-4a38-9f88-ca8b902c7782", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# imports\n", |
||||
"\n", |
||||
"import os\n", |
||||
"import requests\n", |
||||
"#from dotenv import load_dotenv\n", |
||||
"from bs4 import BeautifulSoup\n", |
||||
"from IPython.display import Markdown, display\n", |
||||
"#from openai import OpenAI\n", |
||||
"import ollama\n", |
||||
"# If you get an error running this cell, then please head over to the troubleshooting notebook!" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 11, |
||||
"id": "2a2fdd8c-1333-4a76-9fd5-1fb467c0eaa7", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# A class to represent a Webpage\n", |
||||
"# If you're not familiar with Classes, check out the \"Intermediate Python\" notebook\n", |
||||
"\n", |
||||
"# Some websites need you to use proper headers when fetching them:\n", |
||||
"headers = {\n", |
||||
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36\"\n", |
||||
"}\n", |
||||
"\n", |
||||
"class Website:\n", |
||||
"\n", |
||||
" def __init__(self, url):\n", |
||||
" \"\"\"\n", |
||||
" Create this Website object from the given url using the BeautifulSoup library\n", |
||||
" \"\"\"\n", |
||||
" self.url = url\n", |
||||
" response = requests.get(url, headers=headers)\n", |
||||
" soup = BeautifulSoup(response.content, 'html.parser')\n", |
||||
" self.title = soup.title.string if soup.title else \"No title found\"\n", |
||||
" for irrelevant in soup.body([\"script\", \"style\", \"img\", \"input\"]):\n", |
||||
" irrelevant.decompose()\n", |
||||
" self.text = soup.body.get_text(separator=\"\\n\", strip=True)" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 12, |
||||
"id": "fb4a3de7-196f-4fe7-acb1-55563d8382e6", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"name": "stdout", |
||||
"output_type": "stream", |
||||
"text": [ |
||||
"Home - Edward Donner\n", |
||||
"Home\n", |
||||
"Connect Four\n", |
||||
"Outsmart\n", |
||||
"An arena that pits LLMs against each other in a battle of diplomacy and deviousness\n", |
||||
"About\n", |
||||
"Posts\n", |
||||
"Well, hi there.\n", |
||||
"I’m Ed. I like writing code and experimenting with LLMs, and hopefully you’re here because you do too. I also enjoy DJing (but I’m badly out of practice), amateur electronic music production (\n", |
||||
"very\n", |
||||
"amateur) and losing myself in\n", |
||||
"Hacker News\n", |
||||
", nodding my head sagely to things I only half understand.\n", |
||||
"I’m the co-founder and CTO of\n", |
||||
"Nebula.io\n", |
||||
". We’re applying AI to a field where it can make a massive, positive impact: helping people discover their potential and pursue their reason for being. Recruiters use our product today to source, understand, engage and manage talent. I’m previously the founder and CEO of AI startup untapt,\n", |
||||
"acquired in 2021\n", |
||||
".\n", |
||||
"We work with groundbreaking, proprietary LLMs verticalized for talent, we’ve\n", |
||||
"patented\n", |
||||
"our matching model, and our award-winning platform has happy customers and tons of press coverage.\n", |
||||
"Connect\n", |
||||
"with me for more!\n", |
||||
"January 23, 2025\n", |
||||
"LLM Workshop – Hands-on with Agents – resources\n", |
||||
"December 21, 2024\n", |
||||
"Welcome, SuperDataScientists!\n", |
||||
"November 13, 2024\n", |
||||
"Mastering AI and LLM Engineering – Resources\n", |
||||
"October 16, 2024\n", |
||||
"From Software Engineer to AI Data Scientist – resources\n", |
||||
"Navigation\n", |
||||
"Home\n", |
||||
"Connect Four\n", |
||||
"Outsmart\n", |
||||
"An arena that pits LLMs against each other in a battle of diplomacy and deviousness\n", |
||||
"About\n", |
||||
"Posts\n", |
||||
"Get in touch\n", |
||||
"ed [at] edwarddonner [dot] com\n", |
||||
"www.edwarddonner.com\n", |
||||
"Follow me\n", |
||||
"LinkedIn\n", |
||||
"Twitter\n", |
||||
"Facebook\n", |
||||
"Subscribe to newsletter\n", |
||||
"Type your email…\n", |
||||
"Subscribe\n" |
||||
] |
||||
} |
||||
], |
||||
"source": [ |
||||
"# Let's try one out. Change the website and add print statements to follow along.\n", |
||||
"\n", |
||||
"ed = Website(\"https://edwarddonner.com\")\n", |
||||
"print(ed.title)\n", |
||||
"print(ed.text)" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 13, |
||||
"id": "e6edeaca-9a4d-4d07-aac9-c464976ce519", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# Define our system prompt - you can experiment with this later, changing the last sentence to 'Respond in markdown in Spanish.\"\n", |
||||
"\n", |
||||
"system_prompt = \"You are an assistant that analyzes the contents of a website \\\n", |
||||
"and provides a short summary, ignoring text that might be navigation related. \\\n", |
||||
"Respond in markdown.\"" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 14, |
||||
"id": "574ad4e2-8000-41b9-b732-10c9aacce14e", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# A function that writes a User Prompt that asks for summaries of websites:\n", |
||||
"\n", |
||||
"def user_prompt_for(website):\n", |
||||
" user_prompt = f\"You are looking at a website titled {website.title}\"\n", |
||||
" user_prompt += \"\\nThe contents of this website is as follows; \\\n", |
||||
"please provide a short summary of this website in markdown. \\\n", |
||||
"If it includes news or announcements, then summarize these too.\\n\\n\"\n", |
||||
" user_prompt += website.text\n", |
||||
" return user_prompt" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 15, |
||||
"id": "a8da1d50-9bbe-4ea0-ab89-d4e4909eedbb", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"name": "stdout", |
||||
"output_type": "stream", |
||||
"text": [ |
||||
"You are looking at a website titled Home - Edward Donner\n", |
||||
"The contents of this website is as follows; please provide a short summary of this website in markdown. If it includes news or announcements, then summarize these too.\n", |
||||
"\n", |
||||
"Home\n", |
||||
"Connect Four\n", |
||||
"Outsmart\n", |
||||
"An arena that pits LLMs against each other in a battle of diplomacy and deviousness\n", |
||||
"About\n", |
||||
"Posts\n", |
||||
"Well, hi there.\n", |
||||
"I’m Ed. I like writing code and experimenting with LLMs, and hopefully you’re here because you do too. I also enjoy DJing (but I’m badly out of practice), amateur electronic music production (\n", |
||||
"very\n", |
||||
"amateur) and losing myself in\n", |
||||
"Hacker News\n", |
||||
", nodding my head sagely to things I only half understand.\n", |
||||
"I’m the co-founder and CTO of\n", |
||||
"Nebula.io\n", |
||||
". We’re applying AI to a field where it can make a massive, positive impact: helping people discover their potential and pursue their reason for being. Recruiters use our product today to source, understand, engage and manage talent. I’m previously the founder and CEO of AI startup untapt,\n", |
||||
"acquired in 2021\n", |
||||
".\n", |
||||
"We work with groundbreaking, proprietary LLMs verticalized for talent, we’ve\n", |
||||
"patented\n", |
||||
"our matching model, and our award-winning platform has happy customers and tons of press coverage.\n", |
||||
"Connect\n", |
||||
"with me for more!\n", |
||||
"January 23, 2025\n", |
||||
"LLM Workshop – Hands-on with Agents – resources\n", |
||||
"December 21, 2024\n", |
||||
"Welcome, SuperDataScientists!\n", |
||||
"November 13, 2024\n", |
||||
"Mastering AI and LLM Engineering – Resources\n", |
||||
"October 16, 2024\n", |
||||
"From Software Engineer to AI Data Scientist – resources\n", |
||||
"Navigation\n", |
||||
"Home\n", |
||||
"Connect Four\n", |
||||
"Outsmart\n", |
||||
"An arena that pits LLMs against each other in a battle of diplomacy and deviousness\n", |
||||
"About\n", |
||||
"Posts\n", |
||||
"Get in touch\n", |
||||
"ed [at] edwarddonner [dot] com\n", |
||||
"www.edwarddonner.com\n", |
||||
"Follow me\n", |
||||
"LinkedIn\n", |
||||
"Twitter\n", |
||||
"Facebook\n", |
||||
"Subscribe to newsletter\n", |
||||
"Type your email…\n", |
||||
"Subscribe\n" |
||||
] |
||||
} |
||||
], |
||||
"source": [ |
||||
"print(user_prompt_for(ed))" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 16, |
||||
"id": "4bda2a4b-dace-406e-bd90-3250d04dc664", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# See how this function creates exactly the format above\n", |
||||
"\n", |
||||
"def messages_for(website):\n", |
||||
" return [\n", |
||||
" {\"role\": \"system\", \"content\": system_prompt},\n", |
||||
" {\"role\": \"user\", \"content\": user_prompt_for(website)}\n", |
||||
" ]" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 17, |
||||
"id": "c5f6bd98-3ea8-450d-97f4-346ec7304c42", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"data": { |
||||
"text/plain": [ |
||||
"[{'role': 'system',\n", |
||||
" 'content': 'You are an assistant that analyzes the contents of a website and provides a short summary, ignoring text that might be navigation related. Respond in markdown.'},\n", |
||||
" {'role': 'user',\n", |
||||
" 'content': 'You are looking at a website titled Home - Edward Donner\\nThe contents of this website is as follows; please provide a short summary of this website in markdown. If it includes news or announcements, then summarize these too.\\n\\nHome\\nConnect Four\\nOutsmart\\nAn arena that pits LLMs against each other in a battle of diplomacy and deviousness\\nAbout\\nPosts\\nWell, hi there.\\nI’m Ed. I like writing code and experimenting with LLMs, and hopefully you’re here because you do too. I also enjoy DJing (but I’m badly out of practice), amateur electronic music production (\\nvery\\namateur) and losing myself in\\nHacker News\\n, nodding my head sagely to things I only half understand.\\nI’m the co-founder and CTO of\\nNebula.io\\n. We’re applying AI to a field where it can make a massive, positive impact: helping people discover their potential and pursue their reason for being. Recruiters use our product today to source, understand, engage and manage talent. I’m previously the founder and CEO of AI startup untapt,\\nacquired in 2021\\n.\\nWe work with groundbreaking, proprietary LLMs verticalized for talent, we’ve\\npatented\\nour matching model, and our award-winning platform has happy customers and tons of press coverage.\\nConnect\\nwith me for more!\\nJanuary 23, 2025\\nLLM Workshop – Hands-on with Agents – resources\\nDecember 21, 2024\\nWelcome, SuperDataScientists!\\nNovember 13, 2024\\nMastering AI and LLM Engineering – Resources\\nOctober 16, 2024\\nFrom Software Engineer to AI Data Scientist – resources\\nNavigation\\nHome\\nConnect Four\\nOutsmart\\nAn arena that pits LLMs against each other in a battle of diplomacy and deviousness\\nAbout\\nPosts\\nGet in touch\\ned [at] edwarddonner [dot] com\\nwww.edwarddonner.com\\nFollow me\\nLinkedIn\\nTwitter\\nFacebook\\nSubscribe to newsletter\\nType your email…\\nSubscribe'}]" |
||||
] |
||||
}, |
||||
"execution_count": 17, |
||||
"metadata": {}, |
||||
"output_type": "execute_result" |
||||
} |
||||
], |
||||
"source": [ |
||||
"# Try this out, and then try for a few more websites\n", |
||||
"\n", |
||||
"messages_for(ed)" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 19, |
||||
"id": "e3e1a92a-32e4-4390-8327-77c1f08ba6d9", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"MODEL = \"llama3.2\"" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 20, |
||||
"id": "a2c7f58c-1a81-41a7-83b8-aed9fdd15c08", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# And now: call the OpenAI API. You will get very familiar with this!\n", |
||||
"\n", |
||||
"def summarize(url):\n", |
||||
" website = Website(url)\n", |
||||
" response = ollama.chat(\n", |
||||
" model = MODEL,\n", |
||||
" messages = messages_for(website)\n", |
||||
" )\n", |
||||
" return response['message']['content']" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 21, |
||||
"id": "df110fc8-cbc8-4f76-a393-cdea602a6401", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"data": { |
||||
"text/plain": [ |
||||
"'**Summary**\\n================\\n\\n* Edward Donner is the founder and CTO of Nebula.io, a company applying AI to help people discover their potential.\\n* He has co-founded and worked with various AI startups, including untapt, which was acquired in 2021.\\n\\n**News/Announcements**\\n--------------------\\n\\n* **December 21, 2024**: LLM Workshop – Hands-on with Agents - resources\\n* **November 13, 2024**: Welcome, SuperDataScientists!\\n* **October 16, 2024**: From Software Engineer to AI Data Scientist – resources\\n* **January 23, 2025**: LLM Workshop (upcoming event)\\n\\n**No navigation content has been included in this summary.**'" |
||||
] |
||||
}, |
||||
"execution_count": 21, |
||||
"metadata": {}, |
||||
"output_type": "execute_result" |
||||
} |
||||
], |
||||
"source": [ |
||||
"summarize(\"https://edwarddonner.com\")" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 22, |
||||
"id": "190de7a5-005a-44c5-a10c-c3c2946fbf26", |
||||
"metadata": {}, |
||||
"outputs": [], |
||||
"source": [ |
||||
"# A function to display this nicely in the Jupyter output, using markdown\n", |
||||
"\n", |
||||
"def display_summary(url):\n", |
||||
" summary = summarize(url)\n", |
||||
" display(Markdown(summary))" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 23, |
||||
"id": "d4c743ec-2027-4b87-91aa-67d3125b6f64", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"data": { |
||||
"text/markdown": [ |
||||
"### Website Summary\n", |
||||
"\n", |
||||
"#### Overview\n", |
||||
"The website is owned by Edward Donner, the co-founder and CTO of Nebula.io, a company applying AI to help people discover their potential. The website appears to be a personal blog or portfolio site.\n", |
||||
"\n", |
||||
"#### Content Highlights\n", |
||||
"\n", |
||||
"* **News and Announcements**\n", |
||||
"\t+ Upcoming LLM Workshop on January 23, 2025\n", |
||||
"\t+ Previous workshops: December 21, 2024 (LLM Workshop – Hands-on with Agents), November 13, 2024 (Welcome, SuperDataScientists!), October 16, 2024 (Mastering AI and LLM Engineering)\n", |
||||
"* **Personal Interests**\n", |
||||
"\t+ DJing and amateur electronic music production\n", |
||||
"\t+ Hacker News enthusiast\n", |
||||
"* **Professional Background**\n", |
||||
"\t+ Co-founder and CTO of Nebula.io\n", |
||||
"\t+ Previously founder and CEO of AI startup untapt (acquired in 2021)\n", |
||||
"\n", |
||||
"#### Links\n", |
||||
"\n", |
||||
"* LinkedIn\n", |
||||
"* Twitter\n", |
||||
"* Facebook\n", |
||||
"* Newsletter subscription" |
||||
], |
||||
"text/plain": [ |
||||
"<IPython.core.display.Markdown object>" |
||||
] |
||||
}, |
||||
"metadata": {}, |
||||
"output_type": "display_data" |
||||
} |
||||
], |
||||
"source": [ |
||||
"display_summary(\"https://edwarddonner.com\")" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 24, |
||||
"id": "f877b47b-50ff-4717-a42d-09dbd912c134", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"data": { |
||||
"text/markdown": [ |
||||
"This appears to be the front page of CNN.com, the website for the American cable news channel CNN (Cable News Network). The page is constantly updated with breaking news stories, videos, and analysis on various topics including politics, business, entertainment, sports, and more.\n", |
||||
"\n", |
||||
"Here are some notable features and sections on this page:\n", |
||||
"\n", |
||||
"1. **Headlines**: A section featuring the top news headlines from around the world.\n", |
||||
"2. **Videos**: A collection of short videos related to current events, interviews with newsmakers, and analysis segments.\n", |
||||
"3. **News**: A section that aggregates breaking news stories from various parts of the world.\n", |
||||
"4. **Politics**: A section dedicated to US politics, including presidential elections, legislative updates, and opinion pieces.\n", |
||||
"5. **Business**: A section covering business news, markets, and economic trends.\n", |
||||
"6. **Entertainment**: A section featuring entertainment news, reviews, and analysis on movies, TV shows, music, and celebrities.\n", |
||||
"7. **Sports**: A section dedicated to sports news, scores, and updates on various professional leagues.\n", |
||||
"8. **Features**: A section with in-depth articles, interviews, and profiles on a wide range of topics.\n", |
||||
"9. **Opinion**: A section featuring opinion pieces from CNN's editorial team and other writers on current events and issues.\n", |
||||
"\n", |
||||
"This is just one example of the many ways that CNN presents news to its audience." |
||||
], |
||||
"text/plain": [ |
||||
"<IPython.core.display.Markdown object>" |
||||
] |
||||
}, |
||||
"metadata": {}, |
||||
"output_type": "display_data" |
||||
} |
||||
], |
||||
"source": [ |
||||
"display_summary(\"https://cnn.com\")" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": 25, |
||||
"id": "62ed7fdc-8ff5-4bc4-ae98-81fe22a48ccc", |
||||
"metadata": {}, |
||||
"outputs": [ |
||||
{ |
||||
"data": { |
||||
"text/markdown": [ |
||||
"# Website Summary\n", |
||||
"### Title: Just a Moment...\n", |
||||
"\n", |
||||
"**Overview**\n", |
||||
"The website appears to be under maintenance, requiring users to enable JavaScript and cookies to proceed. No content is displayed until these conditions are met.\n", |
||||
"\n", |
||||
"### News/Announcements (none found)\n", |
||||
"Unfortunately, there are no news or announcements on this website at the time of analysis." |
||||
], |
||||
"text/plain": [ |
||||
"<IPython.core.display.Markdown object>" |
||||
] |
||||
}, |
||||
"metadata": {}, |
||||
"output_type": "display_data" |
||||
} |
||||
], |
||||
"source": [ |
||||
"display_summary(\"https://anthropic.com\")" |
||||
] |
||||
}, |
||||
{ |
||||
"cell_type": "code", |
||||
"execution_count": null, |
||||
"id": "142362ce-77a9-418b-a65d-83e0adb636f1", |
||||
"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 |
||||
} |
Loading…
Reference in new issue