{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6d4fdfa4-bc97-40f9-baf3-121b819f432c",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "acbde373-3a63-4be4-912e-eca6da7e49ab",
   "metadata": {
    "id": "wDRJfXl1u5BS"
   },
   "outputs": [],
   "source": [
    "# from langchain.llms import OpenAI\n",
    "from langchain_openai import ChatOpenAI\n",
    "import openai\n",
    "import os"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "333182d7-1f41-41cf-97e3-d1b06338a57e",
   "metadata": {
    "id": "1H8-3eJ7vMtV"
   },
   "source": [
    "Import the LLM Chat Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4b2654d6-c919-475b-9b87-fba50f81bd69",
   "metadata": {
    "id": "1f4-AOidvVPs"
   },
   "outputs": [],
   "source": [
    "from langchain_openai import OpenAI"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28d39aa9-6d3a-4697-9972-74c6180288c9",
   "metadata": {
    "id": "xeGGxOLevdWh"
   },
   "source": [
    "Environment Variables - API Keys \\\n",
    "It is best to have keys in a folder outside of the folders monitored by \\\n",
    "your source control management system, e.g. git. That way you don't \\\n",
    "publish them. That also allows members of a team to each have their own \\\n",
    "key."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9b151eb2-ce13-49aa-8041-b5e308514075",
   "metadata": {},
   "outputs": [],
   "source": [
    "# The readline() function's output has a '\\n' at the end of the \n",
    "# string so we use the strip() function to get rid of it\n",
    "open_ai_key = open(\"/home/student/Keys/key.txt\", 'r').readline().strip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7a1420bd-223a-49fb-a9b5-3cd6bd7ceb20",
   "metadata": {
    "id": "plqDNxxzviLJ"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ['OPENAI_API_KEY'] = open_ai_key"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a224277a-def2-443a-bb92-44681de89712",
   "metadata": {},
   "source": [
    "Choose a model and assign parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "cbd0c36a-ed99-4126-a693-d80554ff22bd",
   "metadata": {
    "id": "_a6gdMS3wuZ8"
   },
   "outputs": [],
   "source": [
    "# Copy the prompt from the prompt file and paste it here\n",
    "llm = OpenAI(model_name='gpt-4o-mini',\n",
    "             temperature=0,\n",
    "             max_tokens = 256)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd1d94bf-ca8e-468d-9ddd-0048689a046c",
   "metadata": {
    "id": "PzvR-Q0pxATM"
   },
   "source": [
    "Write prompt and print"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "81344c4b-2366-48c7-ae01-37a4c060fb5f",
   "metadata": {
    "id": "1sO7WoqHxDfp"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_10337/1808603314.py:2: LangChainDeprecationWarning: The method `BaseLLM.__call__` was deprecated in langchain-core 0.1.7 and will be removed in 1.0. Use :meth:`~invoke` instead.\n",
      "  result = llm(prompt)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ", and provide a brief description of each.\n",
      "\n",
      "1. **Deep Learning**: A subset of machine learning that uses neural networks with many layers (deep networks) to analyze various forms of data, leading to significant advancements in image and speech recognition.\n",
      "\n",
      "2. **Natural Language Processing (NLP)**: The ability of machines to understand and interpret human language, enabling applications like chatbots, translation services, and sentiment analysis.\n",
      "\n",
      "3. **Reinforcement Learning**: A type of machine learning where an agent learns to make decisions by taking actions in an environment to maximize cumulative reward, leading to advancements in robotics and game playing.\n",
      "\n",
      "4. **Generative Adversarial Networks (GANs)**: A framework where two neural networks (a generator and a discriminator) compete against each other to create realistic data, revolutionizing fields like image generation and video synthesis.\n",
      "\n",
      "5. **Computer Vision**: The ability of machines to interpret and understand visual information from the world, leading to advancements in facial recognition, autonomous vehicles, and medical image analysis.\n",
      "\n",
      "6. **Transfer Learning**: A technique that allows a model trained on one task to be reused on a different but related task, significantly reducing the amount of data and time needed for training.\n",
      "\n",
      "7. **Explainable AI (XAI)**\n"
     ]
    }
   ],
   "source": [
    "prompt = \"List the Top 10 AI breakthroughs. List them in number form\"\n",
    "result = llm(prompt)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7ac8997-a091-449e-bfb5-86bb1b99c4e4",
   "metadata": {},
   "source": [
    "We are only interested in the value of content attribute of the object returned so a prettier output is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21cbe790-9bbf-45d1-a396-eae946364480",
   "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.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
