Merge pull request #656 from shiv-konar/feature/learning-llm-engineering

adding new day 1 exercise
This commit is contained in:
Ed Donner
2025-09-19 19:37:17 -04:00
committed by GitHub

View File

@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4a9842d0-2465-4c0a-9f08-3c23f4202c3a",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from dotenv import load_dotenv\n",
"from IPython.display import Markdown, display\n",
"from openai import OpenAI"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7fcfe08c-d074-41f5-befe-24358c967e1b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "89fd124d-5e7b-4e61-af85-2fe978c688f2",
"metadata": {},
"outputs": [],
"source": [
"system_prompt = \"You are an analyst that analyzes the financial transactions data and provides summary of where the money has been spent, where money can be cut back so savings be increased\"\n",
"user_prompt = \"\"\"\n",
" data = [\n",
" {\"transaction_id\": 1, \"date\": \"2025-01-05\", \"merchant\": \"Amazon\", \"category\": \"Shopping\", \"amount\": -120.50, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 2, \"date\": \"2025-01-07\", \"merchant\": \"Starbucks\", \"category\": \"Food & Drink\", \"amount\": -4.75, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 3, \"date\": \"2025-01-09\", \"merchant\": \"Tesco\", \"category\": \"Groceries\", \"amount\": -56.20, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 4, \"date\": \"2025-01-10\", \"merchant\": \"Uber\", \"category\": \"Transport\", \"amount\": -15.80, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 5, \"date\": \"2025-01-15\", \"merchant\": \"Apple\", \"category\": \"Electronics\", \"amount\": -899.00, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 6, \"date\": \"2025-01-18\", \"merchant\": \"Netflix\", \"category\": \"Subscription\", \"amount\": -9.99, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 7, \"date\": \"2025-01-20\", \"merchant\": \"Salary\", \"category\": \"Income\", \"amount\": 2500.00, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 8, \"date\": \"2025-01-22\", \"merchant\": \"British Airways\", \"category\": \"Travel\", \"amount\": -450.00, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 9, \"date\": \"2025-01-25\", \"merchant\": \"Marks & Spencer\", \"category\": \"Shopping\", \"amount\": -75.30, \"currency\": \"GBP\"},\n",
" {\"transaction_id\": 10, \"date\": \"2025-01-30\", \"merchant\": \"HMRC\", \"category\": \"Tax\", \"amount\": -320.00, \"currency\": \"GBP\"},\n",
"]\n",
"\n",
"\n",
"\"\"\"\n",
"\n",
"# Step 2: Make the messages list\n",
"\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 = openai.chat.completions.create(\n",
" model = \"gpt-4o-mini\",\n",
" messages = messages\n",
" )\n",
"\n",
"# Step 4: print the result\n",
"\n",
"display(Markdown(response.choices[0].message.content))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12d6642e-a4d4-49c7-a14b-8c8200dd210c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5fccacf-ddb4-4076-87cc-0ffe6a4d64a4",
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}