{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Implementing Notebook 1 using various LLMs via Groq" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from dotenv import load_dotenv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "openai_api_key = os.getenv('OPENAI_API_KEY')\n", "groq_api_key = os.getenv('GROQ_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 - please head to the troubleshooting guide in the setup folder\")\n", "\n", "if groq_api_key:\n", " print(f\"Groq API Key exists and begins {groq_api_key[:2]}\")\n", "else:\n", " print(\"Groq API Key not set - please head to the troubleshooting guide in the setup folder\")\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from openai import OpenAI" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "openai = OpenAI(\n", " base_url=\"https://api.groq.com/openai/v1\",\n", " api_key=groq_api_key\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# And now - let's ask for a question:\n", "\n", "question = \"Please propose a hard, challenging question to assess someone's IQ. Respond only with the question.\"\n", "messages = [{\"role\": \"user\", \"content\": question}]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# openai/gpt-oss-120b\n", "\n", "response = openai.chat.completions.create(\n", " model=\"openai/gpt-oss-120b\",\n", " messages=messages\n", ")\n", "\n", "print(response.choices[0].message.content)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# moonshotai/kimi-k2-instruct\n", "\n", "response = openai.chat.completions.create(\n", " model=\"moonshotai/kimi-k2-instruct\",\n", " messages=messages\n", ")\n", "\n", "question = response.choices[0].message.content\n", "\n", "print(question)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# form a new messages list\n", "messages = [{\"role\": \"user\", \"content\": question}]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Ask meta-llama/llama-guard-4-12b\n", "\n", "response = openai.chat.completions.create(\n", " model=\"llama-3.1-8b-instant\",\n", " messages=messages\n", ")\n", "\n", "answer = response.choices[0].message.content\n", "print(answer)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Markdown, display\n", "\n", "display(Markdown(question))\n", "display(Markdown(answer))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
" ![]() | \n",
" \n",
" Exercise\n", " Now try this commercial application:\n", " First ask the LLM to pick a business area that might be worth exploring for an Agentic AI opportunity. \n", " Then ask the LLM to present a pain-point in that industry - something challenging that might be ripe for an Agentic solution. \n", " Finally have 3 third LLM call propose the Agentic AI solution. \n", " We will cover this at up-coming labs, so don't worry if you're unsure.. just give it a try!\n", " \n", " | \n",
"