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

@@ -497,6 +497,26 @@
"display_summary(\"https://anthropic.com\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a904323-acd9-4c8e-9a17-70df76184590",
"metadata": {},
"outputs": [],
"source": [
"display_summary(\"https://rwothoromo.wordpress.com/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a66c9fe8-c26a-49dd-9bc4-9efffc638f95",
"metadata": {},
"outputs": [],
"source": [
"display_summary(\"https://openai.com\")"
]
},
{
"cell_type": "markdown",
"id": "c951be1a-7f1b-448f-af1f-845978e47e2c",
@@ -538,23 +558,55 @@
"source": [
"# Step 1: Create your prompts\n",
"\n",
"system_prompt = \"something here\"\n",
"system_prompt = \"You are a professional assistant\"\n",
"user_prompt = \"\"\"\n",
" Lots of text\n",
" Can be pasted here\n",
"Review this conversation and provide a comprehensive summary. Also, suggest how much better the converation could have gone:\n",
"\n",
"Dear Dev Contact,\n",
"\n",
"I hope this message finds you well.\n",
"I would like to share that I have proficiency in front-end design tools, particularly Figma, react and Angular. At this stage, I am keenly interested in finding opportunities to apply these skills professionally.\n",
"\n",
"If you are aware of any companies, projects, or platforms seeking enterprise in front-end design, I would be grateful for any advice or recommendations you might kindly provide.\n",
"\n",
"Thank you very much for your time and consideration.\n",
"\n",
"Hello Job Seeker,\n",
"\n",
"I hope you are doing well.\n",
"\n",
"Dev Contact: The last role (3 months gig) I saw was looking for a junior PHP Developer. Does your CV include that?\n",
"\n",
"Hello Dev Contact \n",
"Thank you for your feedback.\n",
"Yes my CV has PHP as one of my skill set. Can I share it with you?\n",
"\n",
"Dev Contact: They said \"It's late. Interviews were on Monday\"\n",
"\n",
"Hello Dev Contact\n",
"\n",
"Thanks for the update. When you hear of any opportunity please let me know.\n",
"\n",
"Dev Contact: For now, check out https://refactory.academy/courses/refactory-apprenticeship/\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",
"] # fill this in\n",
"\n",
"# Step 3: Call OpenAI\n",
"\n",
"response =\n",
"response = openai.chat.completions.create(\n",
" model = \"gpt-4o-mini\",\n",
" messages = messages\n",
")\n",
"\n",
"# Step 4: print the result\n",
"\n",
"print("
"print(response.choices[0].message.content)"
]
},
{
@@ -588,6 +640,34 @@
"id": "f4484fcf-8b39-4c3f-9674-37970ed71988",
"metadata": {},
"outputs": [],
"source": [
"# To perform summaries using a model running locally\n",
"import ollama\n",
"\n",
"# OLLAMA_API = \"http://localhost:11434/api/chat\"\n",
"# HEADERS = {\"Content-Type\": \"application/json\"}\n",
"MODEL = \"llama3.2\"\n",
"\n",
"\n",
"def summarize_with_local_model(url):\n",
" website = Website(url)\n",
" messages = messages_for(website)\n",
" response = ollama.chat(\n",
" model=MODEL,\n",
" messages=messages,\n",
" stream=False # just get the results, don't stream them\n",
" )\n",
" return response['message']['content']\n",
"\n",
"display(Markdown(summarize_with_local_model(\"https://rwothoromo.wordpress.com/\")))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e76cbf31-2a82-40b8-b2e7-e2ceae7483ed",
"metadata": {},
"outputs": [],
"source": []
}
],
@@ -607,7 +687,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.12"
"version": "3.11.7"
}
},
"nbformat": 4,