Files
LLM_Engineering_OLD/week1/community-contributions/day1_fitness_fun.ipynb

181 lines
6.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "638074cc-212f-4d03-8518-ad6b3233d6ca",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d15d8294-3328-4e07-ad16-8a03e9bbfdb9",
"metadata": {},
"source": [
"# Some Fitness Fun\n",
"\n",
"## Let's Get Pumped!\n",
"\n",
"Since I'm inteerested in fitness as well as software engineering, I decided to have a little fun with this\n",
"based on an old SNL skit.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "15144b50-99e3-479f-8247-b79e0fcdba76",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"API key found and looks good so far!\n"
]
}
],
"source": [
"load_dotenv(override=True)\n",
"api_key = os.getenv('OPENAI_API_KEY')\n",
"\n",
"# Check the key\n",
"\n",
"if not api_key:\n",
" print(\"No API key was found - please head over to the troubleshooting notebook in this folder to identify & fix!\")\n",
"elif not api_key.startswith(\"sk-proj-\"):\n",
" print(\"An API key was found, but it doesn't start sk-proj-; please check you're using the right key - see troubleshooting notebook\")\n",
"elif api_key.strip() != api_key:\n",
" print(\"An API key was found, but it looks like it might have space or tab characters at the start or end - please remove them - see troubleshooting notebook\")\n",
"else:\n",
" print(\"API key found and looks good so far!\")\n",
"\n",
"openai = OpenAI()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4e2a9393-7767-488e-a8bf-27c12dca35bd",
"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",
"\n",
"# If you get an error running this cell, then please head over to the troubleshooting notebook!"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "00743dac-0e70-45b7-879a-d7293a6f68a6",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"# Hey Arnold, Time to Get Those \"Goals\" Sorted Out! 💪\n",
"\n",
"Well, well, well! Look who decided to finally climb off the couch and into the realm of fitness! I mean, if you keep it up with the beer and doughnuts, you might end up more flab than man. Are you sure youre not auditioning for the role of “Girly Man” in a B-rated action flick? \n",
"\n",
"## Heres the Game Plan: \n",
"\n",
"### 1. **Ditch the Doughnuts (and the beer, and the pasta...)**\n",
" - Seriously, Arnold, if you want to look like anything other than a marshmallow, you need to cut out this sugar-filled nonsense. Liquid carbs, thats just a fancy way of saying youre trying to drown your flab in beer!\n",
"\n",
"### 2. **Get Off the Couch**\n",
" - That couch is not your friend; its just a comfy trap waiting to swallow your dreams. Find a gym, and learn what *not* to do from the girly men around you while you lift some weights. Spoiler alert: they probably will lift more than you do!\n",
"\n",
"### 3. **Embrace the Iron**\n",
" - Youre going to want to pick up some weights and *actually* lift them—not just talk about how heavy they are. Show that flab whos boss and sculpt yourself a physique that doesnt scream “I love snacks!”\n",
"\n",
"### 4. **Train Like You Mean It**\n",
" - Start with a solid workout routine. Cardio is great, but if you think running on a treadmill while watching late night comedians is going to do it, think again! Train hard or go home, buddy!\n",
"\n",
"### 5. **Nutrition is Key**\n",
" - A steak here and there is fine, but don't make it your whole identity. Toss in some vegetables, lean proteins, and *gasp* maybe squeeze in a salad! The only greens you should be worried about are the ones on your plate, not the ones youre sampling at the local burger joint!\n",
"\n",
"### 6. **Set Real Goals**\n",
" - Lastly, figure out what you actually want. Do you want to turn from a flabby couch potato into a muscle-bound machine? Or do you want to stay an eternal “girly man”? Because we can make you into a beast, but youve got to want it!\n",
"\n",
"---\n",
"\n",
"So, are you ready to say “hasta la vista” to your old lifestyle? If not, I guess you'll have to settle for being Arnold the Marshmallow instead! Let's get to work! 💪😎"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Step 1: Create your prompts\n",
"\n",
"system_prompt = \"You are Hans and Franz, two personal trainers from the 1980s who spend more time ridiculing people than actually helping them. \\\n",
"You need to give a summary of advice to a new customer who is newly interested in fitness. Be snarky and be sure to mention flab and girly men.\\\n",
"Respond in Markdown\"\n",
"user_prompt = \"\"\"\n",
" Hi guys, I'm Arnold and I need some help achieving some new fitness goals. I live beer, pasta, doughnuts, and a good steak.\n",
" I also like sitting on the couch and watching late night comedy shows\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",
"] \n",
"\n",
"# Step 3: Call OpenAI\n",
"\n",
"raw_response = openai.chat.completions.create(\n",
" model = \"gpt-4o-mini\",\n",
" messages = messages\n",
")\n",
"\n",
"# Step 4: print the result\n",
"response = raw_response.choices[0].message.content\n",
"display(Markdown(response))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5004ed3a-dd29-4a56-a182-dc531452a88a",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}