{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# First Agentic AI workflow with Groq and Llama-3.3 LLM(Free of cost) " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# First let's do an import\n", "from dotenv import load_dotenv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Next it's time to load the API keys into environment variables\n", "\n", "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Check the Groq API key\n", "\n", "import os\n", "groq_api_key = os.getenv('GROQ_API_KEY')\n", "\n", "if groq_api_key:\n", " print(f\"GROQ API Key exists and begins {groq_api_key[:8]}\")\n", "else:\n", " print(\"GROQ API Key not set\")\n", " \n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# And now - the all important import statement\n", "# If you get an import error - head over to troubleshooting guide\n", "\n", "from groq import Groq" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Create a Groq instance\n", "groq = Groq()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Create a list of messages in the familiar Groq format\n", "\n", "messages = [{\"role\": \"user\", \"content\": \"What is 2+2?\"}]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# And now call it!\n", "\n", "response = groq.chat.completions.create(model='llama-3.3-70b-versatile', messages=messages)\n", "print(response.choices[0].message.content)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "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}]\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# ask it\n", "response = groq.chat.completions.create(\n", " model=\"llama-3.3-70b-versatile\",\n", " messages=messages\n", ")\n", "\n", "question = response.choices[0].message.content\n", "\n", "print(question)\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# form a new messages list\n", "messages = [{\"role\": \"user\", \"content\": question}]\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Ask it again\n", "\n", "response = groq.chat.completions.create(\n", " model=\"llama-3.3-70b-versatile\",\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(answer))\n", "\n" ] }, { "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", " \n", " | \n",
"