From 024d474643d54225ae850ddd2dba0f9656b2af63 Mon Sep 17 00:00:00 2001 From: Rohit Nain Date: Sun, 24 Aug 2025 11:37:07 +0530 Subject: [PATCH] added email summaizers script with openai --- .../Day-1_email_summarizers.ipynb | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 week1/community-contributions/Day-1_email_summarizers.ipynb diff --git a/week1/community-contributions/Day-1_email_summarizers.ipynb b/week1/community-contributions/Day-1_email_summarizers.ipynb new file mode 100644 index 0000000..d2a4597 --- /dev/null +++ b/week1/community-contributions/Day-1_email_summarizers.ipynb @@ -0,0 +1,103 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d7a6bb51", + "metadata": {}, + "outputs": [], + "source": [ + "# import library\n", + "from openai import OpenAI\n", + "import os\n", + "from dotenv import load_dotenv\n", + "\n", + "# Load your API key from an .env file\n", + "load_dotenv(override=True)\n", + "api_key = os.getenv('OPENAI_API_KEY')\n", + "openai = OpenAI()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ac4cdf9", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "# Step 1: Create your prompts\n", + "system_prompt = \"you are a helpful assistant that suggests an appropriate short subject line for an email based on its contents.\"\n", + "\n", + "user_prompt = \"\"\"\n", + "Hi John,\n", + "I hope this email finds you well. I wanted to follow up on our meeting last week regarding the quarterly budget proposal.\n", + "After reviewing the numbers with my team, we've identified some areas where we can reduce costs by approximately 15% without impacting our core operations. This would involve consolidating some vendor contracts and optimizing our software licensing.\n", + "Could we schedule a meeting next week to discuss these findings in detail? I'm available Tuesday through Thursday afternoon.\n", + "Looking forward to hearing from you.\n", + "\n", + "Best regards,\n", + "Sarah\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a77ca09e", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "# Step 2: Make the messages list\n", + "messages = [\n", + " {\"role\": \"system\", \"content\": system_prompt},\n", + " {\"role\": \"user\", \"content\": user_prompt}\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8404f0fe", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "# Step 3: Call OpenAI\n", + "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a4875f7", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "# Step 4: Print the result\n", + "print(response.choices[0].message.content)" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}