{ "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", " \n", " \n", "
\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", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# First create the messages:\n", "\n", "messages = [{\"role\": \"user\", \"content\": \"Pick a business area that is worth exploring for a Gen-Z audience, that can be an agentic-ai opportunity. \\\n", " Somehwere where the concept of agentisation can be applied commerically. Respond only with the business idea.\"}]\n", "\n", "# Then make the first call: \n", "\n", "response = openai.chat.completions.create(\n", " model = \"qwen/qwen3-32b\",\n", " messages = messages\n", ")\n", "\n", "# Then read the business idea:\n", "\n", "business_idea = response.choices[0].message.content\n", "print(business_idea)\n", "\n", "# And repeat! In the next message, include the business idea within the message\n", "\n", "user_prompt_pain_point = f\"What is the pain point of the Gen-Z audience in the business area of {business_idea}?, that can be solved by an agentic-ai solution? Give a brief answer\"\n", "\n", "response = openai.chat.completions.create(\n", " model = \"gemma2-9b-it\",\n", " messages = [{\"role\": \"user\", \"content\": user_prompt_pain_point}]\n", ")\n", "\n", "pain_point = response.choices[0].message.content\n", "print(pain_point)\n", "\n", "user_prompt_solution = f\"What is the solution to the pain point {pain_point} of the Gen-Z audience in the business area of {business_idea}?, that can be solved by an agentic-ai solution? Provide a step-by-step breakdown\"\n", "\n", "response = openai.chat.completions.create(\n", " model = \"deepseek-r1-distill-llama-70b\",\n", " messages = [{\"role\": \"user\", \"content\": user_prompt_solution}]\n", ")\n", "\n", "business_solution = response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display(Markdown(business_solution))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }