Day 9 · 1 Hour
LLM & Prompt Engineering
Groq API, system prompts, temperature — talk to an LLM the way engineers do, not users.
🔥 Real-World Hook (0–5 min)
Two people ask ChatGPT to write a Python function. One gets a 10-line vague answer. The other gets a production-ready function with docstring, type hints, and edge case handling. Same model. Different prompt.
Prompt engineering is the new skill gap. Companies pay ₹15–25 LPA for engineers who know how to instruct LLMs reliably. Today you learn the difference.
📈 Prompt Engineering Principles (5–25 min)
| Technique | What it does | Example |
|---|---|---|
| System prompt | Sets personality & constraints | "You are a senior Python developer..." |
| Few-shot | Show examples before the task | Input/output pairs |
| Chain-of-thought | Ask for reasoning steps | "Think step by step" |
| Temperature 0 | Deterministic output | Code, JSON, facts |
| Temperature 0.7+ | Creative output | Stories, brainstorming |
💻 Live Demo — Code Review Bot (25–45 min)
>from groq import Groq import os client = Groq(api_key=os.getenv("GROQ_API_KEY")) # System prompt defines the LLM's role and behaviour SYSTEM = "You are a senior Python code reviewer at a top tech company. Review code for: correctness, PEP8 style, edge cases, performance. Be specific. Rate each issue: Critical / Warning / Suggestion. Keep response under 200 words." code_to_review = " def get_user(users, id): for u in users: if u["id"] == id: return u return None " response = client.chat.completions.create( model="llama3-8b-8192", temperature=0, # deterministic for code review messages=[ {"role": "system", "content": SYSTEM}, {"role": "user", "content": f"Review this Python code:\n{code_to_review}" } ] ) print(response.choices[0].message.content) # Few-shot: teach the model the exact output format few_shot_msgs = [ {"role": "user", "content": "Classify: Free iPhone click here!!!"}, {"role": "assistant", "content": "SPAM"}, {"role": "user", "content": "Classify: Meeting at 3pm tomorrow"}, {"role": "assistant", "content": "HAM"}, {"role": "user", "content": "Classify: Congratulations you won a prize!"}, ]
📋 You Code It (45–55 min)
✍ Task
Write a prompt that converts a plain English description into a Python function signature with type hints. Test it on: "a function that takes a list of names and returns them sorted with duplicates removed". Try temperature 0 vs 0.9 — observe the difference.
⚡ Day 9 Cheat Sheet
Groq(api_key=os.getenv(...))Create Groq client
client.chat.completions.create()Call the LLM
messages=[{role, content}]Conversation turns
role: "system"Set personality/constraints
temperature=0Deterministic output
temperature=0.7Creative output
response.choices[0].message.contentGet text response
max_tokens=200Limit response length