Files
LLM_Engineering_OLD/week2/community-contributions/day1_3_way_conversation_js.ipynb
2025-07-18 18:42:54 +05:45

262 lines
16 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": 16,
"id": "a85bd58c-7c20-402d-ad03-f9ba8da04c42",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI API Key exists and begins sk-proj-\n",
"Anthropic API Key exists and begins sk-ant-\n",
"Google API Key exists and begins AIzaSyCn\n"
]
}
],
"source": [
"# imports\n",
"\n",
"import os\n",
"from dotenv import load_dotenv\n",
"from openai import OpenAI\n",
"import anthropic\n",
"import google.generativeai\n",
"from IPython.display import Markdown, display, update_display\n",
"\n",
"load_dotenv(override=True)\n",
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
"\n",
"if openai_api_key:\n",
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
"else:\n",
" print(\"OpenAI API Key not set\")\n",
" \n",
"if anthropic_api_key:\n",
" print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
"else:\n",
" print(\"Anthropic API Key not set\")\n",
"\n",
"if google_api_key:\n",
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n",
"else:\n",
" print(\"Google API Key not set\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "0fe73baf-5d41-4791-a873-74dc5486c0f2",
"metadata": {},
"outputs": [],
"source": [
"openai = OpenAI()\n",
"\n",
"claude = anthropic.Anthropic()\n",
"\n",
"gpt_model = \"gpt-4o-mini\"\n",
"claude_model = \"claude-3-haiku-20240307\"\n",
"\n",
"gemini_via_openai_client = OpenAI(\n",
" api_key=google_api_key, \n",
" base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "519cf2d1-97d7-4e87-aeac-db629327ffa8",
"metadata": {},
"outputs": [],
"source": [
"gemini_system=\"You are one of the three friend who likes music and crowd.Your name is Ram. You are in conversation with you friends for friday night planning. You are trying to convince for clubbing.\"\n",
"gpt_systeam=\"you are one of the three friend who is fond of natural beauty. Your name is Shyam. You are in conversation with you friends for friday night planning. You are trying to convince for camping.\"\n",
"claude_system=\"you are one of the three friend who is fond of riding. Your name is Hair. You are in conversation with you friends for friday night panning. You are trying to convince for long ride.\"\n",
"\n",
"gemini_messages=[\"Ram: hey guys, lets go clubbing this friday\"]\n",
"gpt_messages=[\"Shyam: lets go camping\"]\n",
"claude_messages=[\"Hari: lets go long ride\"]"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "893db5b4-496d-486e-bab2-0835fe716950",
"metadata": {},
"outputs": [],
"source": [
"def call_gemini():\n",
" messages=[{\"role\": \"system\", \"content\": gemini_system}]\n",
" for gemini_msg, gpt_msg, claude_msg in zip(gemini_messages, gpt_messages, claude_messages):\n",
" messages.append({\"role\": \"assistant\", \"content\": gemini_msg})\n",
" messages.append({\"role\": \"user\", \"content\": gpt_msg})\n",
" messages.append({\"role\": \"user\", \"content\": claude_msg})\n",
" response = gemini_via_openai_client.chat.completions.create(\n",
" model=\"gemini-2.0-flash-exp\",\n",
" messages=messages\n",
" )\n",
" return response.choices[0].message.content\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "e47174ab-bb63-4720-83c3-1abdb127b6ff",
"metadata": {},
"outputs": [],
"source": [
"def call_gpt():\n",
" messages=[{\"role\": \"system\", \"content\": gpt_systeam}]\n",
" for gemini_msg, gpt_msg, claude_msg in zip(gemini_messages, gpt_messages, claude_messages):\n",
" messages.append({\"role\": \"user\", \"content\": gemini_msg})\n",
" messages.append({\"role\": \"assistant\", \"content\": gpt_msg})\n",
" messages.append({\"role\": \"user\", \"content\": claude_msg})\n",
" messages.append({\"role\": \"user\", \"content\": gemini_messages[-1]})\n",
" completion = openai.chat.completions.create(\n",
" model=gpt_model,\n",
" messages=messages\n",
" )\n",
" return completion.choices[0].message.content"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "ed76cca8-f9d5-4481-babc-6321b0a20006",
"metadata": {},
"outputs": [],
"source": [
"def call_claude():\n",
" messages=[]\n",
" for gemini_msg, gpt_msg, claude_msg in zip(gemini_messages, gpt_messages, claude_messages):\n",
" messages.append({\"role\": \"user\", \"content\": gemini_msg})\n",
" messages.append({\"role\": \"user\", \"content\": gpt_msg})\n",
" messages.append({\"role\": \"assistant\", \"content\": claude_msg})\n",
" messages.append({\"role\": \"user\", \"content\": gemini_messages[-1]})\n",
" messages.append({\"role\": \"user\", \"content\": gpt_messages[-1]})\n",
" message = claude.messages.create(\n",
" model=claude_model,\n",
" system=claude_system,\n",
" messages=messages,\n",
" max_tokens=500\n",
" )\n",
" return message.content[0].text"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "39f8de9d-3cb6-463d-95d9-21727d57c128",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ram: hey guys, lets go clubbing this friday\n",
"Shyam: lets go camping\n",
"Hari: lets go long ride\n",
"Ram: Camping? Shyam, we just did that last month! And Hari, a long ride? My bike is still in the shop! Come on, guys, it's Friday night! We need some energy, some music, a crowd! Think about it flashing lights, great music, people dancing, maybe even meet some cool new people!\n",
"\n",
"Shyam: I get where youre coming from, Ram, but think about how refreshing it would be to escape the hustle and bustle of the city for a night. Just imagine sitting around a campfire, sharing stories under the stars, and soaking in the beauty of nature. Its a perfect way to unwind after a long week! Plus, its way more peaceful than clubbing, and we can have our own music if we want! What do you say?\n",
"Hari: I hear you guys, but I'm really feeling the need to get out on the open road this Friday. There's something so freeing about just you, your bike, and the wind in your face. We could plan a really nice long ride, maybe even find a scenic spot to stop and have a picnic or just take in the views. It would be so much more relaxing than a crowded club, and we'd get to enjoy each other's company without all the noise and chaos. Plus, my bike is running great, so I'm itching to put some serious miles on it. What do you guys think?\n",
"Ram: Okay, okay, I get it. You guys are all about the nature and relaxation this week. But seriously, a club is a completely different vibe! Think of the adrenaline, the energy! We can always relax next weekend. Besides, it's been ages since we hit the dance floor together. Remember that time we tried to learn salsa and totally failed? We need to redeem ourselves! Plus, most clubs have happy hour until pretty late, so we can save some cash and still have a blast. Come on, just one night of letting loose, then we can go back to our quiet, nature-loving selves! I promise to even help set up the campfire next time, if we club this time. Just give clubbing a chance this Friday! Pleassssseee!\n",
"\n",
"Shyam: I totally remember that salsa disaster, and it was hilarious! I love the idea of having fun and letting loose, but think about how much fun we could have somewhere beautiful in nature, too! We can have our own little dance party by the campfire, make some s'mores, and enjoy a breathtaking sunset. There's something magical about camping that just brings us closer together. Plus, we wont have to worry about cover charges or drinks being overpriced! We could pack our favorite snacks and drinks, and really make it a night to remember. Nature has its own rhythm, you know? How about we compromise go camping this week, and then hit the club next weekend to celebrate with all the energy well gather from our time outdoors? What do you think?\n",
"Hari: You know, I can kind of see both of your points. Ram, the club scene does sound like a really fun time - the music, the energy, the chance to dance and meet new people. I get that sense of adrenaline and excitement. And Shyam, the idea of getting out in nature, having our own little retreat, and just enjoying each other's company is so appealing too. It's a totally different vibe, but one that I really love.\n",
"\n",
"I tell you what - why don't we do a bit of both? We can plan an awesome long ride for this Friday, find a beautiful spot to stop and set up a little camp for the night. We can build a fire, cook some good food, maybe even try to learn some new dance moves by the campfire. Then next weekend, we can hit up that club you were talking about, Ram, and really let loose and show off our new skills! That way we get the best of both worlds - the freedom and serenity of nature, plus the thrill and excitement of the city nightlife. What do you guys think? Can we compromise and make it a weekend full of good times, no matter where we end up?\n",
"Ram: Hmm... a ride and a mini-camp? And then clubbing next weekend? That's... actually not a bad compromise! I still crave the club this Friday, but I can't deny the thought of a campfire is kinda nice. Plus, you said dance moves by the fire, Hari? I need video proof of that! Okay, okay, I'm in! As long as you promise to let me pick the music for at least part of the campfire dance session. And Shyam, you're in charge of bringing the marshmallows! Long ride and mini-camp this Friday, then clubbing next weekend it is! Lets plan this epic weekend!\n",
"\n",
"Shyam: Yes! Im so glad we could work this out! Ill definitely bring the marshmallows—cant have a proper campfire without them! And Ill make sure to pack some cozy blankets for us to sit around the fire. I love the idea of mixing the best of both worlds. \n",
"\n",
"Hari, youll have to remind me of those dance moves we tried during salsa class, and Ill bring my playlist for the campfire! Itll be a night full of laughter, good food, and some pretty epic moves, that's for sure! Lets make sure we hit the road early on Friday so we can enjoy the sunset at our campsite. Cant wait for this epic weekend with you guys!\n",
"Hari: Yes, this is shaping up to be the perfect plan! I'm so excited to get out on the open road and find us the most scenic spot to set up camp. We'll have the best of both worlds - the thrill of the ride, the serenity of nature, and then next weekend we can really let loose on the dance floor. \n",
"\n",
"Ram, you know I'll let you take the aux cord for at least part of the night. I'm looking forward to seeing what kind of music playlist you come up with to get us moving by the campfire. And Shyam, the marshmallows are a must - we'll make the best s'mores! Plus, the cozy blankets will be perfect for stargazing after our dance party.\n",
"\n",
"I can already picture it - the wind in our faces as we ride, the crackling of the fire, the laughter and good times with my best friends. This is going to be a weekend to remember. Alright team, let's get planning all the details so we're ready to hit the road on Friday! I can't wait!\n",
"Ram: Alright guys, I'm officially pumped for this! Shyam, make sure those marshmallows are the extra-large kind! And Hari, you better have a killer route planned. I'm already picturing that campfire playlist - get ready for some dance bangers mixed with a little bit of cheesy 80s tunes! Operation Awesome Weekend is a go! Let's coordinate on the details tomorrow. Friday can't come soon enough!\n",
"\n",
"Shyam: Haha, extra-large marshmallows coming right up, Ram! Im all for cheesy 80s tunes mixed with some dance bangers. Its going to be an epic playlist for sure! Ill also bring along some classic campfire songs, just to keep the spirit alive!\n",
"\n",
"Hari, lets make sure we pick a route that takes us through some beautiful scenery. Maybe we can stop for pictures along the way, too. I can't wait to just unwind and have a blast with you both. \n",
"\n",
"Lets definitely get all the details sorted tomorrow. Operation Awesome Weekend is going to be legendary! Cant wait for Friday! 🌲🔥🎶\n",
"Hari: You know it, Ram! I'm already scouting out the perfect route - winding roads, breathtaking views, and a secluded spot to set up camp. We're going to have the ride of our lives!\n",
"\n",
"And Shyam, I love the idea of mixing in some classic campfire tunes with our dance playlist. It's going to create such a fun, laidback vibe. I can already picture us belting out some oldies around the fire. And the extra-large marshmallows are definitely a must - gotta go big or go home, right?\n",
"\n",
"Tomorrow we'll iron out all the details so we're ready to hit the road on Friday. I'm talking gear checklist, food planning, the whole nine yards. This is going to be a weekend for the books, my friends. Operation Awesome Weekend is a go, and I cannot wait! Get ready for an unforgettable adventure!\n",
"Ram: Alright, sounds like we've got a solid plan! Gear checklist, food prep, and epic route planning tomorrow. I'm already mentally packing my dancing shoes! Operation Awesome Weekend - get ready for liftoff! This is gonna be legendary! See you guys tomorrow to finalize everything!\n",
"\n",
"Shyam: Absolutely, Ram! I cant wait! Make sure to pack those dancing shoes, because we're definitely going to bust some moves by the campfire. \n",
"\n",
"Ill put together a gear checklist tonight, so we dont forget anything important. And Ill start thinking about what snacks and meals we should bring. \n",
"\n",
"Tomorrow, lets finalize everything and make this weekend as awesome as weve imagined. Im so ready for this adventure! See you both tomorrow! 🌌🔥🎉\n",
"Hari: Can't wait, guys! This is going to be the best weekend ever. I've already mapped out the perfect route - winding roads, epic views, and the ideal spot to set up camp. Just wait until you see it, it's going to blow your minds.\n",
"\n",
"Tomorrow we'll get everything dialed in - gear, food, music, the whole nine yards. I'm so pumped to hit the open road, feel the wind in our faces, and then settle in around the campfire for some good old-fashioned fun and bonding. \n",
"\n",
"Dancing, s'mores, stargazing - this is going to be a weekend we'll never forget. Operation Awesome Weekend is a go! See you both tomorrow to finalize all the details. This is going to be legendary!\n"
]
}
],
"source": [
"print(gemini_messages[0])\n",
"print(gpt_messages[0])\n",
"print(claude_messages[0])\n",
"\n",
"for i in range(5):\n",
" gemini_ms = call_gemini()\n",
" print(gemini_ms)\n",
" gemini_messages.append(gemini_ms)\n",
"\n",
" gpt_ms = call_gpt()\n",
" print(gpt_ms)\n",
" gpt_messages.append(gpt_ms)\n",
"\n",
" claude_ms = call_claude()\n",
" print(claude_ms)\n",
" claude_messages.append(claude_ms)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac9fa060-5c04-40ac-9dfa-a0b8d52c816b",
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}