Week 1 exercise

This commit is contained in:
Elijah Rwothoromo
2025-08-05 20:42:50 +03:00
parent 3a042500d7
commit 9da9692a9b
7 changed files with 649 additions and 79 deletions

View File

@@ -144,6 +144,15 @@
" {\"type\": \"careers page\", \"url\": \"https://another.full.url/careers\"}\n",
" ]\n",
"}\n",
"\"\"\"\n",
"link_system_prompt += \"And this example:\"\n",
"link_system_prompt += \"\"\"\n",
"{\n",
" \"links\": [\n",
" {\"type\": \"for-you page\", \"url\": \"https://full.url/goes/here/services\"},\n",
" {\"type\": \"speak-to-a-human page\", \"url\": \"https://another.full.url/contact-us\"}\n",
" ]\n",
"}\n",
"\"\"\""
]
},
@@ -213,6 +222,9 @@
"source": [
"# Anthropic has made their site harder to scrape, so I'm using HuggingFace..\n",
"\n",
"# anthropic = Website(\"https://anthropic.com\")\n",
"# anthropic.links\n",
"# get_links(\"https://anthropic.com\")\n",
"huggingface = Website(\"https://huggingface.co\")\n",
"huggingface.links"
]
@@ -272,15 +284,15 @@
"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",
"# 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"
"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"
]
},
{
@@ -293,6 +305,7 @@
"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 += f\"Keep the details brief or concise, factoring in that they would be printed on a simple hand-out flyer.\\n\"\n",
" user_prompt += get_all_details(url)\n",
" user_prompt = user_prompt[:5_000] # Truncate if more than 5,000 characters\n",
" return user_prompt"
@@ -324,6 +337,28 @@
" ],\n",
" )\n",
" result = response.choices[0].message.content\n",
" # display(Markdown(result))\n",
" # print(result)\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0029e063-0c07-4712-82d9-536ec3579e80",
"metadata": {},
"outputs": [],
"source": [
"def translate_brochure(brochure, language):\n",
" system_prompt_for_language = \"You're an expert in \" + language + \". Translate the brochure!\"\n",
" response = openai.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": system_prompt_for_language},\n",
" {\"role\": \"user\", \"content\": brochure}\n",
" ],\n",
" )\n",
" result = response.choices[0].message.content\n",
" display(Markdown(result))"
]
},
@@ -337,6 +372,28 @@
"create_brochure(\"HuggingFace\", \"https://huggingface.co\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8371bf5-c4c0-4e52-9a2a-066d994b0510",
"metadata": {},
"outputs": [],
"source": [
"brochure = create_brochure(\"Paint and Sip Uganda\", \"https://paintandsipuganda.com/\")\n",
"# translate_brochure(brochure, \"Spanish\")\n",
"translate_brochure(brochure, \"Swahili\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "34e03db6-61d0-4fc5-bf66-4f679b9befde",
"metadata": {},
"outputs": [],
"source": [
"create_brochure(\"Wabeh\", \"https://wabeh.com/\")"
]
},
{
"cell_type": "markdown",
"id": "61eaaab7-0b47-4b29-82d4-75d474ad8d18",
@@ -501,7 +558,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
"version": "3.11.7"
}
},
"nbformat": 4,