From 0ca5d2181e13660e6bb67dd237dd4875f8e4b0a4 Mon Sep 17 00:00:00 2001 From: mikeulator Date: Thu, 12 Dec 2024 16:53:52 -0800 Subject: [PATCH 1/2] week 1 --- week1/Guide to Jupyter.ipynb | 2 +- week1/day1.ipynb | 4 +- week1/day2 EXERCISE.ipynb | 2 +- week1/day2challenge.py | 63 ++++++++++++++++ week1/day5-llama3.2-result.md | 42 +++++++++++ week1/day5-llama3.3-result.md | 32 ++++++++ week1/day5.ipynb | 2 +- week1/day5.py | 134 ++++++++++++++++++++++++++++++++++ 8 files changed, 276 insertions(+), 5 deletions(-) create mode 100644 week1/day2challenge.py create mode 100644 week1/day5-llama3.2-result.md create mode 100644 week1/day5-llama3.3-result.md create mode 100644 week1/day5.py diff --git a/week1/Guide to Jupyter.ipynb b/week1/Guide to Jupyter.ipynb index 0f0ddf2..61da613 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.11" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/week1/day1.ipynb b/week1/day1.ipynb index 2c2e1c2..08d74e3 100644 --- a/week1/day1.ipynb +++ b/week1/day1.ipynb @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "4e2a9393-7767-488e-a8bf-27c12dca35bd", "metadata": {}, "outputs": [], @@ -559,7 +559,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.11" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/week1/day2 EXERCISE.ipynb b/week1/day2 EXERCISE.ipynb index 4504401..c6fcc9e 100644 --- a/week1/day2 EXERCISE.ipynb +++ b/week1/day2 EXERCISE.ipynb @@ -222,7 +222,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.11" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/week1/day2challenge.py b/week1/day2challenge.py new file mode 100644 index 0000000..1c78639 --- /dev/null +++ b/week1/day2challenge.py @@ -0,0 +1,63 @@ +import ollama +import os +import requests + +from bs4 import BeautifulSoup +from IPython.display import Markdown, display + +MODEL = "llama3.2:3b-instruct-q8_0" + +messages = [ + {"role": "user", "content": "Describe some of the business applications of Generative AI"} +] + +# response = ollama.chat(model=MODEL, messages=messages) +# print(response['message']['content']) +class Website: + + def __init__(self, url): + """ + Create this Website object from the given url using the BeautifulSoup library + """ + self.url = url + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + self.title = soup.title.string if soup.title else "No title found" + try: + for irrelevant in soup.body(["script", "style", "img", "input"]): + irrelevant.decompose() + except: + pass + self.text = soup.body.get_text(separator="\n", strip=True) + +system_prompt = "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." + +def user_prompt_for(website): + user_prompt = f"You are looking at a website titled {website.title}" + user_prompt += "\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\n" + user_prompt += website.text + return user_prompt + +def messages_for(website): + return [ + {"role": "system", "content": system_prompt}, + {"role": "user", "content": user_prompt_for(website)} + ] + +def summarize(url): + website = Website(url) + response = ollama.chat( + model = MODEL, + messages = messages_for(website) + ) + return response['message']['content'] + +def display_summary(url): + summary = summarize(url) + print(summary) + +display_summary("https://mike-tupper.com/") \ No newline at end of file diff --git a/week1/day5-llama3.2-result.md b/week1/day5-llama3.2-result.md new file mode 100644 index 0000000..0ad50b1 --- /dev/null +++ b/week1/day5-llama3.2-result.md @@ -0,0 +1,42 @@ +This appears to be a press release archive or news feed from Anthropic, a company that specializes in developing large language models and artificial intelligence. Here's a summary of the key points: + +**Company Overview** + +* Anthropic is a leader in developing AI models that can understand and generate human-like language. +* The company has developed several AI models, including Claude, which is a conversational AI model designed to assist with various tasks. + +**Product Updates** + +* Claude: A conversational AI model that can be used for a variety of tasks, including customer service, data enrichment, and more. New versions of Claude have been released regularly, including: + + Claude 2 (available on Amazon Bedrock) + + Claude 3 (features improved performance and new capabilities) + + Claude 3 Haiku (a faster version of Claude 3) + + Claude Pro (an enterprise-level version of Claude) + +**Partnerships and Collaborations** + +* Anthropic has partnered with several companies, including: + + Amazon Web Services (AWS) to integrate Claude into AWS's services + + Accenture to develop trusted solutions for enterprises + + BCG (Boston Consulting Group) to expand access to safer AI + + SKT (Samsung Electronics) on a partnership announcement + +**Industry Recognition** + +* Anthropic has received recognition from industry leaders and experts, including: + + Dario Amodei's prepared remarks from the AI Safety Summit on Anthropic's Responsible Scaling Policy + + Thoughts on the US Executive Order, G7 Code of Conduct, and Bletchley Park Summit by Anthropic + +**Safety and Ethics** + +* Anthropic has emphasized its commitment to safety and ethics in AI development, including: + + Expanding access to safer AI with Amazon + + Releasing a Responsible Scaling Policy + + Aligning on child safety principles + +**Other News** + +* Anthropic has also made headlines for other reasons, such as: + + Introducing Claude Android app + + Fine-tuning Claude 3 Haiku in Amazon Bedrock + + Evaluating prompts in the developer console \ No newline at end of file diff --git a/week1/day5-llama3.3-result.md b/week1/day5-llama3.3-result.md new file mode 100644 index 0000000..a0c9ec3 --- /dev/null +++ b/week1/day5-llama3.3-result.md @@ -0,0 +1,32 @@ +Based on the provided webpage contents, here is a summary of the information: + +**About Anthropic** + +* Anthropic is a company that develops large-scale AI systems. +* Their research teams aim to create safer, steerable, and more reliable models. + +**Careers** + +* Anthropic has a careers page that lists open roles across various teams and offices. +* The company values direct evidence of ability, such as independent research, blog posts, or open-source software contributions. +* They do not require PhDs, degrees, or previous ML experience for technical staff positions. +* About half of the technical staff have a PhD, and about half had prior experience in ML. +* Anthropic sponsors visas and green cards for eligible candidates. + +**Interview Process** + +* Interviews are conducted over Google Meet, with a preference for PST office hours. +* Candidates can re-apply after 12 months if they are not successful initially. +* The company does not provide feedback on resumes or interviews. + +**Remote Work** + +* Anthropic staff typically come to the office regularly, but some may work remotely part-time or full-time. +* The company understands that moving can take time and offers a transitional phase for remote workers. + +**Research** + +* Anthropic's research teams focus on developing safer, steerable, and more reliable large-scale AI systems. +* The company is working at the frontier of AI research and development. + +Overall, Anthropic appears to be a company that values innovation, expertise, and diversity in its workforce. They prioritize creating safe and reliable AI systems and offer opportunities for career growth and development. \ No newline at end of file diff --git a/week1/day5.ipynb b/week1/day5.ipynb index 3cdc54a..259100e 100644 --- a/week1/day5.ipynb +++ b/week1/day5.ipynb @@ -475,7 +475,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.11" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/week1/day5.py b/week1/day5.py new file mode 100644 index 0000000..ba38638 --- /dev/null +++ b/week1/day5.py @@ -0,0 +1,134 @@ +import ollama +import os +import requests +import json + +from bs4 import BeautifulSoup +from IPython.display import Markdown, display + +""" +Available Models: +llama3.3:latest a6eb4748fd29 42 GB 24 hours ago +granite3-moe:3b 157f538ae66e 2.1 GB 2 weeks ago +granite3-dense:8b 199456d876ee 4.9 GB 2 weeks ago +nemotron:70b-instruct-q5_K_M def2cefbe818 49 GB 6 weeks ago +llama3.2:3b-instruct-q8_0 e410b836fe61 3.4 GB 7 weeks ago +llama3.2:latest a80c4f17acd5 2.0 GB 2 months ago +reflection:latest 5084e77c1e10 39 GB 3 months ago +HammerAI/llama-3.1-storm:latest 876631929cf6 8.5 GB 3 months ago +granite-code:34b 4ce00960ca84 19 GB 3 months ago +llama3.1:8b 91ab477bec9d 4.7 GB 3 months ago +llama3.1-Q8-8b:latest 3d41179680d6 8.5 GB 3 months ago +nomic-embed-text:latest 0a109f422b47 274 MB 3 months ago +rjmalagon/gte-qwen2-7b-instruct-embed-f16:latest a94ce5b37c1c 15 GB 3 months ago +llama3:70b-instruct-q5_K_M 4e84a5514862 49 GB 3 months ago +llama3:8b 365c0bd3c000 4.7 GB 3 months ago +mistral-nemo:12b-instruct-2407-q8_0 b91eec34730f 13 GB 3 months ago +""" + +MODEL = "llama3.3" + +messages = [ + {"role": "user", "content": "Describe some of the business applications of Generative AI"} +] + +# response = ollama.chat(model=MODEL, messages=messages) +# print(response['message']['content']) +class Website: + """ + A utility class to represent a website that we have scraped, now with links + """ + url: str + title: str + body: str + links: list[str] + text: str + + def __init__(self, url): + self.url = url + response = requests.get(url) + self.body = response.content + soup = BeautifulSoup(self.body, 'html.parser') + self.title = soup.title.string if soup.title else "No title found" + if soup.body: + try: + for irrelevant in soup.body(["script", "style", "img", "input"]): + irrelevant.decompose() + self.text = soup.body.get_text(separator="\n", strip=True) + except: + pass + else: + self.text = "" + links = [link.get('href') for link in soup.find_all('a')] + self.links = [link for link in links if link] + + def get_contents(self): + return f"Webpage Title:\n{self.title}\nWebpage Contents:\n{self.text}\n\n" + +link_system_prompt = "You are provided with a list of links found on a webpage. \ +You are able to decide which of the links would be most relevant to include in a brochure about the company, \ +such as links to an About page, or a Company page, or Careers/Jobs pages.\n" +link_system_prompt += "You should respond in JSON as in this example:" +link_system_prompt += """ +{ + "links": [ + {"type": "about page", "url": "https://full.url/goes/here/about"}, + {"type": "careers page": "url": "https://another.full.url/careers"} + ] +} +""" + +def get_links_user_prompt(website): + user_prompt = f"Here is the list of links on the website of {website.url} - " + 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. \ + Do not include Terms of Service, Privacy, email links.\n" + user_prompt += "Links (some might be relative links):\n" + user_prompt += "\n".join(website.links) + return user_prompt + +def get_links(url): + website = Website(url) + response = ollama.chat( + model=MODEL, + messages=[ + {"role": "system", "content": link_system_prompt}, + {"role": "user", "content": get_links_user_prompt(website)} + ], + format="json" + ) + result = response['message']['content'] + return json.loads(result) + +def get_all_details(url): + result = "Landing page:\n" + result += Website(url).get_contents() + links = get_links(url) + # print("Found links:", links) + for link in links["links"]: + result += f"\n\n{link['type']}\n" + result += Website(link["url"]).get_contents() + return result + +system_prompt = "You are an assistant that analyzes the contents of several relevant pages from a company website \ +and creates a short professional sales brochure about the company for prospective customers, investors and recruits. Respond \ +in markdown. Include details of company culture, customers and careers/jobs if you have the information." + +def get_brochure_user_prompt(company_name, url): + user_prompt = f"You are looking at a company called: {company_name}\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" + user_prompt += get_all_details(url) + user_prompt = user_prompt[:20000] # Truncate if more than 5,000 characters + return user_prompt + +def create_brochure(company_name, url): + response = ollama.chat( + model=MODEL, + messages=[ + {"role": "system", "content": system_prompt}, + {"role": "user", "content": get_brochure_user_prompt(company_name, url)} + ], + ) + result = response['message']['content'] + print(result) + +create_brochure("Anthropic", "https://anthropic.com") \ No newline at end of file From afcfec9b4170508dae084f0e35f623fa4904ca7c Mon Sep 17 00:00:00 2001 From: mikeulator Date: Thu, 12 Dec 2024 17:01:35 -0800 Subject: [PATCH 2/2] bogus --- week1/day5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week1/day5.py b/week1/day5.py index ba38638..f627b03 100644 --- a/week1/day5.py +++ b/week1/day5.py @@ -131,4 +131,4 @@ def create_brochure(company_name, url): result = response['message']['content'] print(result) -create_brochure("Anthropic", "https://anthropic.com") \ No newline at end of file +create_brochure("Anthropic", "https://anthropic.com")