0–5 min
Real Hook
5–25 min
Core Concept
25–45 min
Live Coding
45–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)

Groq runs LLaMA 3 at 800 tokens per second — that's faster than reading. For free.

Every startup building AI features in India right now is using Groq for speed and cost. Today you add an AI feature to your Django app in 12 lines of Python — a student doubt assistant that answers programming questions instantly.

🌐 LLM = Function Call that Returns Text (5–25 min)

💡 Demystified

An LLM API is just a POST request. You send: {"model": "llama3", "messages": [{"role": "user", "content": "Explain recursion"}]}. You get back: {"content": "Recursion is a function calling itself..."}. That's it. No magic — just HTTP.

💻 Live Coding — AI Doubt Assistant (25–45 min)

# pip install groq
from groq import Groq

client = Groq(api_key="your-groq-api-key")

def ask_ai(question):
    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {"role": "system", "content": "You are a Python tutor helping beginners. Be concise and use code examples."},
            {"role": "user",   "content": question}
        ]
    )
    return response.choices[0].message.content

# Test it
answer = ask_ai("What is the difference between a list and a tuple in Python?")
print(answer)
# Django view: POST /api/ask/ → returns AI answer
from rest_framework.views import APIView
from rest_framework.response import Response
from groq import Groq

client = Groq(api_key=settings.GROQ_API_KEY)

class AskAIView(APIView):
    def post(self, request):
        question = request.data.get("question", "")
        if not question:
            return Response({"error": "question required"}, status=400)

        response = client.chat.completions.create(
            model="llama-3.3-70b-versatile",
            messages=[
                {"role": "system", "content": "You are a Python tutor. Be concise."},
                {"role": "user",   "content": question}
            ]
        )
        answer = response.choices[0].message.content
        return Response({"answer": answer})
🎯 You Code It (45–55 min)
  1. Create a free Groq account at console.groq.com and get an API key
  2. Install: pip install groq
  3. Test the ask_ai() function with 3 Python questions from your notebook
  4. Add AskAIView to your Django project, wire up POST /api/ask/
  5. Build a simple HTML chat interface: text input + submit → fetch /api/ask/ → show response
  6. Bonus: Add conversation history — store previous Q&A in a list and pass all messages to the API
  7. Show: Working chat interface answering Python questions using Groq

📄 Day 14 Cheat Sheet — Groq LLM API

Groq Setup

pip install groqInstall
from groq import GroqImport
Groq(api_key="...")Create client
store key in .envNever hardcode
console.groq.comFree API key

Chat Completion

client.chat.completions.create()Main call
model="llama-3.3-70b-versatile"Fastest free model
messages=[{role, content}]Conversation array
role: "system"Set AI persona
role: "user"User message
role: "assistant"AI's prior reply

Response

response.choices[0]First choice
.message.contentThe text reply
response.usage.total_tokensTokens used
max_tokens=500Limit response length
temperature=0.7Creativity (0=deterministic)

Prompt Engineering

system promptSets AI's role and style
"Be concise"Shorter answers
"Use code examples"More code in response
"Explain to a beginner"Simpler language
conversation historyPass all prior messages