From e741dcf7b6885b9ef0b466401532998685e360b2 Mon Sep 17 00:00:00 2001 From: yashupatel1998 Date: Mon, 24 Mar 2025 16:03:32 -0400 Subject: [PATCH 1/2] Added new notebooks to community-contributions with cleared outputs --- .../Day 1_Code_generation_llm.ipynb | 199 ++++++++++++++++++ .../day-1-Stock-data-analysis.ipynb | 91 +++++++- .../day-1-generate-cover-letter-from-cv.ipynb | 18 +- 3 files changed, 296 insertions(+), 12 deletions(-) create mode 100644 week1/community-contributions/Day 1_Code_generation_llm.ipynb diff --git a/week1/community-contributions/Day 1_Code_generation_llm.ipynb b/week1/community-contributions/Day 1_Code_generation_llm.ipynb new file mode 100644 index 0000000..1736c5f --- /dev/null +++ b/week1/community-contributions/Day 1_Code_generation_llm.ipynb @@ -0,0 +1,199 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "0a2cd326-08fd-4f28-b0a3-b343691bda16", + "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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0a5f3e89-6a79-4fb2-be72-ed67d340a38c", + "metadata": {}, + "outputs": [], + "source": [ + "# Load environment variables in a file called .env\n", + "\n", + "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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b42f2583-7f15-435b-8ab6-315ae9f316cf", + "metadata": {}, + "outputs": [], + "source": [ + "openai = OpenAI()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ee959e1-22ef-42dd-9c98-edda119729e8", + "metadata": {}, + "outputs": [], + "source": [ + "def ask_ai(prompt):\n", + " \"\"\" Function to send a prompt to OpenAI and return the response \"\"\"\n", + " try:\n", + " response = openai.chat.completions.create(\n", + " model=\"gpt-4o-mini\",\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": \"You are an advanced AI assistant specialized in software development. You generate complete, optimized, and well-documented code for any requested approach, ensuring best practices, efficiency, and scalability. You provide explanations alongside the code, highlighting important concepts and potential improvements.\"},\n", + " {\"role\": \"user\", \"content\": prompt}\n", + " ]\n", + " )\n", + " return response.choices[0].message.content\n", + " except Exception as e:\n", + " return f\"Error: {e}\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bae8d4aa-7a29-4087-b6af-2e90cb0d9b0d", + "metadata": {}, + "outputs": [], + "source": [ + "# Run the AI assistant in a loop\n", + "print(\"AI Coding Assistant: Type 'exit' to stop\")\n", + "while True:\n", + " user_input = input(\"\\nYou: \")\n", + " \n", + " if user_input.lower() == \"exit\":\n", + " print(\"Goodbye!\")\n", + " break\n", + "\n", + " response = ask_ai(user_input)\n", + "# Display output in Markdown format\n", + " display(Markdown(response))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5fa23de-670e-4dcb-a237-5b7398ae638d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74e73c7c-8488-49b6-b7ec-1a9e68348a45", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0b949382-4f23-4f12-bd59-5231f68725e7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "09a21202-01a9-418a-8177-3a7f8dd8f643", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a44c7b69-d361-425e-b9e6-3edbea9f6949", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7867fb13-ac3e-43c9-aeb1-414d3d5f330b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50fa0835-842f-49ca-9c91-cd3fd52e765e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "44ca77da-cd34-4bd2-912a-71fb548ada86", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "deb595bf-cf2a-4798-88df-1b4fe06cb0f7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77a0e0fe-5e65-41d6-a3ee-b1ef96b44394", + "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 +} diff --git a/week1/community-contributions/day-1-Stock-data-analysis.ipynb b/week1/community-contributions/day-1-Stock-data-analysis.ipynb index 1c3a39f..cb8a09e 100644 --- a/week1/community-contributions/day-1-Stock-data-analysis.ipynb +++ b/week1/community-contributions/day-1-Stock-data-analysis.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "4e2a9393-7767-488e-a8bf-27c12dca35bd", "metadata": {}, "outputs": [], @@ -35,10 +35,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "7b87cadb-d513-4303-baee-a37b6f938e4d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "API key found and looks good so far!\n" + ] + } + ], "source": [ "# Load environment variables in a file called .env\n", "\n", @@ -59,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "019974d9-f3ad-4a8a-b5f9-0a3719aea2d3", "metadata": {}, "outputs": [], @@ -69,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "51d42a08-188e-4c56-9578-47cd549bd1d8", "metadata": {}, "outputs": [], @@ -84,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "682eff74-55c4-4d4b-b267-703edbc293c7", "metadata": {}, "outputs": [], @@ -121,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "70b8d7e7-51e7-4392-9b85-9ac9f67a907c", "metadata": {}, "outputs": [], @@ -145,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "de514421-4cc8-4881-85b4-97f03e94c589", "metadata": {}, "outputs": [], @@ -165,10 +173,73 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "41acc36f-484a-4257-a240-cf27520e7396", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "## Stock Performance Analysis for GOOG\n", + "\n", + "The following is an analysis based on the provided data from the weekly performance of Google (GOOG) stock over a year. Here’s a breakdown of the key trends and observations:\n", + "\n", + "### Key Data Metrics\n", + "\n", + "- **Date Range**: The last recorded week was on March 21, 2025.\n", + "- **Opening Price**: The price at which the stock opened at the start of the period was generally high, around $163.32.\n", + "- **Closing Price**: The closing price also displayed variability with a notable peak reaching as high as $206.25 at some points.\n", + "- **High and Low Prices**: Price variation indicates several peaks and troughs, with highs occasionally exceeding $200, while lows dipped to around $148.\n", + "\n", + "### Summary of Trends\n", + "\n", + "1. **Overall Upward Trend**:\n", + " - Starting from around $150 on March 25, 2024, the stock reached approximately $166 by March 21, 2025. This suggests a gradual increase in the stock price over this period despite fluctuations.\n", + " \n", + "2. **Price Volatility**:\n", + " - The stock experienced several fluctuations where the high price during the week often exceeded $200, signaling periods of strong market interest.\n", + " - The lows reflected corrections; for instance, the lowest weekly closing was around $148, suggesting some weeks where buying pressure was lower.\n", + "\n", + "3. **Volume Trends**:\n", + " - There was a considerable trading volume in many weeks, especially during price fluctuations. The weekly volumes often surpassed tens of millions, showing active trading.\n", + "\n", + "4. **Dividends**:\n", + " - There were multiple dividends noted (e.g., $0.20 per share weeks), reflecting a strategy to share profits with shareholders.\n", + "\n", + "### Returns Calculation\n", + "\n", + "To calculate the total returns based on closing prices:\n", + "\n", + "- **Starting Price (Closing Price on March 25, 2024)**: $152.26\n", + "- **Ending Price (Closing Price on March 21, 2025)**: $166.25\n", + "\n", + "#### Calculation:\n", + "\n", + "\\[\n", + "\\text{Total Return} = \\left(\\frac{\\text{Ending Price} - \\text{Starting Price}}{\\text{Starting Price}}\\right) \\times 100\n", + "\\]\n", + "\n", + "Substituting the values in:\n", + "\n", + "\\[\n", + "\\text{Total Return} = \\left(\\frac{166.25 - 152.26}{152.26}\\right) \\times 100 \\approx \\left(\\frac{13.99}{152.26}\\right) \\times 100 \\approx 9.17\\%\n", + "\\]\n", + "\n", + "### Conclusion\n", + "\n", + "- **Total Returns**: An investor in GOOG could have expected approximately **9.17%** total returns over the analyzed period.\n", + "- The continued interest in Google stock, indicated by consistent trading volumes and dividends, along with the upward trajectory, suggests that it remains a strong candidate for investors looking to hold positions in tech stocks.\n", + "\n", + "This summary reflects the trends and performance of Google's stock based on the provided data, offering insights into trading behaviors and potential investment opportunities." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "display_analysis(\"GOOG\")" ] diff --git a/week1/community-contributions/day-1-generate-cover-letter-from-cv.ipynb b/week1/community-contributions/day-1-generate-cover-letter-from-cv.ipynb index 09ed71b..ab481d8 100644 --- a/week1/community-contributions/day-1-generate-cover-letter-from-cv.ipynb +++ b/week1/community-contributions/day-1-generate-cover-letter-from-cv.ipynb @@ -110,10 +110,24 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "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": 2 + "nbformat_minor": 4 } From d89a2b9159f0bb590db11a0625f381aabc4b21b2 Mon Sep 17 00:00:00 2001 From: yashupatel1998 Date: Tue, 25 Mar 2025 18:06:53 -0400 Subject: [PATCH 2/2] Added my contributions to community-contributions --- .../Day 1_Code_generation_llm.ipynb | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/week1/community-contributions/Day 1_Code_generation_llm.ipynb b/week1/community-contributions/Day 1_Code_generation_llm.ipynb index 1736c5f..02d458a 100644 --- a/week1/community-contributions/Day 1_Code_generation_llm.ipynb +++ b/week1/community-contributions/Day 1_Code_generation_llm.ipynb @@ -7,14 +7,13 @@ "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" + "import openai \n", + "import ollama " ] }, { @@ -48,7 +47,8 @@ "metadata": {}, "outputs": [], "source": [ - "openai = OpenAI()" + "# Initialize OpenAI\n", + "openai_client = openai.OpenAI(api_key=api_key)" ] }, { @@ -73,6 +73,29 @@ " return f\"Error: {e}\"" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "421c4ebe-7017-4ac8-b4d1-7837e1a68223", + "metadata": {}, + "outputs": [], + "source": [ + "# Function to ask Ollama\n", + "def ask_ollama(prompt):\n", + " \"\"\" send a prompt to ollama and return the response \"\"\"\n", + " try:\n", + " response = ollama.chat(\n", + " model=\"llama3.2\",\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": \"You are an advanced AI assistant specialized in software development. You generate complete, optimized, and well-documented code for any requested approach, ensuring best practices, efficiency, and scalability. You provide explanations alongside the code, highlighting important concepts and potential improvements.\"},\n", + " {\"role\": \"user\", \"content\": prompt}\n", + " ]\n", + " )\n", + " return response['message']['content']\n", + " except Exception as e:\n", + " return f\"Ollama Error: {e}\" " + ] + }, { "cell_type": "code", "execution_count": null, @@ -89,9 +112,13 @@ " print(\"Goodbye!\")\n", " break\n", "\n", - " response = ask_ai(user_input)\n", - "# Display output in Markdown format\n", - " display(Markdown(response))" + " print(\"\\n **OpenAI Response:**\")\n", + " openai_response = ask_ai(user_input)\n", + " display(Markdown(openai_response))\n", + "\n", + " print(\"\\n **Ollama Response:**\")\n", + " ollama_response = ask_ollama(user_input)\n", + " display(Markdown(ollama_response))" ] }, {