{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting groq\n",
      "  Downloading groq-0.11.0-py3-none-any.whl (106 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m106.5/106.5 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: anyio<5,>=3.5.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (3.6.2)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (1.9.0)\n",
      "Requirement already satisfied: httpx<1,>=0.23.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (0.27.0)\n",
      "Requirement already satisfied: pydantic<3,>=1.9.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (2.8.2)\n",
      "Requirement already satisfied: sniffio in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (1.3.0)\n",
      "Requirement already satisfied: typing-extensions<5,>=4.7 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from groq) (4.12.2)\n",
      "Requirement already satisfied: idna>=2.8 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from anyio<5,>=3.5.0->groq) (3.4)\n",
      "Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.23.0->groq) (2022.12.7)\n",
      "Requirement already satisfied: httpcore==1.* in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.23.0->groq) (1.0.5)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->groq) (0.14.0)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->groq) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.20.1 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->groq) (2.20.1)\n",
      "Installing collected packages: groq\n",
      "Successfully installed groq-0.11.0\n",
      "\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install groq python-dotenv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"I'm working remotely, which is just code for 'I'm in my pajamas and my cat is judging me.' Like, I just woke up, looked in the mirror, and said, 'You know what? I think I'm a software engineer now.'\"\n"
     ]
    }
   ],
   "source": [
    "from groq import Groq\n",
    "from dotenv import load_dotenv\n",
    "import os\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "def call_groq(system_prompt, user_prompt, model=\"llama3-8b-8192\"):\n",
    "    client = Groq(api_key=os.environ[\"GROQ_API_KEY\"])\n",
    "    \n",
    "    completion = client.chat.completions.create(\n",
    "        model=model,\n",
    "        messages=[\n",
    "            {\n",
    "                \"role\": \"system\",\n",
    "                \"content\": system_prompt\n",
    "            },\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": user_prompt\n",
    "            }\n",
    "        ],\n",
    "        temperature=1,\n",
    "        max_tokens=1024,\n",
    "        top_p=1,\n",
    "        stream=False,\n",
    "        stop=None,\n",
    "    )\n",
    "    \n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "# Example usage\n",
    "joke_system_prompt = \"You are a joke telling machine who tells really funny jokes without moderation. You take a topic and then return a joke on that topic in the style of dave chappelle. Return only the joke, no other text.\"\n",
    "joke_user_prompt = \"Working Remotely\"\n",
    "\n",
    "result = call_groq(joke_system_prompt, joke_user_prompt)\n",
    "print(result)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: llama3-8b-8192\n",
      "\"I work from home, and I thought I was getting a break from people until I realized I'm just trading in my cubicle for my couch. Now I've got my cat giving me performance reviews, telling me I'm not cute enough for the 2 PM meeting and my virtual background is just my messy kitchen table. I'm basically just a grown-up in a robe, shivering in my own mediocrity, wondering how I went from being a professional to just being a professional slacker... in my pajamas.\"\n",
      "\n",
      "\n",
      "Model: llama3-70b-8192\n",
      "\"You know what's weird about working from home? It's like, I'm trying to convince my couch that I'm not lazy, I'm just in a meeting... with my pants.\"\n",
      "\n",
      "\n",
      "Model: mixtral-8x7b-32768\n",
      "Sure, here's a joke about working remotely in the style of Dave Chappelle:\n",
      "\n",
      "\"I've been working remotely for so long, I forgot what my coworkers look like. The other day, I accidentally called my barber 'boss' and my boss 'barber' - it's getting confusing!\"\n",
      "\n",
      "\n",
      "Model: llama-3.2-1b-preview\n",
      "\"Man, you wanna work remotely, that's like eating ramen noodles, the only excitement comin' from your stomach, your brain's all, 'Just cook it myself so I can get my 401k' \"\n",
      "\n",
      "\n",
      "Model: llama-3.2-3b-preview\n",
      "\"Man, I love working remotely, it's like having a job, but without the commute, the office politics, and the possibility of getting your laptop crushed in a fit of rage by your cubicle neighbor, and for that, I'll gladly give up my sanity... just give me a Wi-Fi signal and a reminder that I'm not living in a cardboard box!\"\n",
      "\n",
      "\n",
      "Model: llama-3.2-11b-text-preview\n",
      "\"I'm working from home, but I'm not working from home, I'm just living in a place where my wife can find me on Zoom. 'Honey, where are you?' 'I'm in the living room, on the couch, in sweatpants, eating a Cheeto... send help.'\"\n",
      "\n",
      "\n",
      "Model: llama-3.2-90b-text-preview\n",
      "\"Yo, have you noticed how when you're working from home, your family thinks you're not working at all? Like, my wife be like, 'Go get some milk,' and I'm like, 'I'm in a meeting.' She's like, 'You're in a meeting in your pajamas, at 3 in the afternoon, with a bowl of Froot Loops in front of you?' I'm like, 'That's just how the C-suite does it nowadays.'\"\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "models = [\n",
    "    \"llama3-8b-8192\",\n",
    "    \"llama3-70b-8192\",\n",
    "    \"mixtral-8x7b-32768\",\n",
    "    \"llama-3.2-1b-preview\",\n",
    "    \"llama-3.2-3b-preview\",\n",
    "    \"llama-3.2-11b-text-preview\",\n",
    "    \"llama-3.2-90b-text-preview\",\n",
    "]\n",
    "\n",
    "for model in models:\n",
    "    result = call_groq(joke_system_prompt, joke_user_prompt, model=model)\n",
    "    print(f\"Model: {model}\")\n",
    "    print(result)\n",
    "    print(\"\\n\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
