π Iteration is Essential
When AI output doesn't match expectations:
β Don't immediately change the code
β First improve the prompt
π€ Generate Output
β
π Evaluate Result
β
βοΈ Adjust Prompt
β
π Generate Again
β
π Repeat until satisfied
π― Prompt iteration is one of the most important skills when building AI applications!
π§ͺ Notebook vs Production Development
π Notebook Style β "Data Scientist Mode" π¬
In notebooks, we act as experimenters, not engineers. Variables are defined globally and freely overridden as we iterate:
# Define it...
SYSTEM_PROMPT = "You are a helpful assistant."
# Didn't like it? Just overwrite it! π
SYSTEM_PROMPT = "You are a funny assistant."
# Still not right? Override again! π
SYSTEM_PROMPT = "You are a pirate assistant. Arrr! π΄ββ οΈ"π§ As a data scientist, you're exploring and experimenting β the goal is to find what works, not to write clean code. Global variables are a shortcut that makes iteration fast and frictionless.
β Great for...
β‘ Fast experimentation
π§ͺ Rapid prompt testing
βοΈ Quick tweaks without restructuring
π Production Style β "Software Engineer Mode" π·
As a software developer, overriding global variables is a red flag π©. Instead, everything is structured, controlled, and reusable:
# β
Prompts live inside functions/classes β never floating globally
class BrochureGenerator:
def __init__(self, system_prompt: str):
self.system_prompt = system_prompt # injected, not hardcoded
def generate(self, company_name: str, url: str):
...
Pattern | Purpose |
|---|---|
π§± Classes | Organize logic cleanly |
π§ Functions | Reusable, testable code |
π Dependency Injection | Pass prompts in β don't hardcode them |
βοΈ Config Management | Manage prompts & settings from one place |
π‘ Streaming Protocols
Generated tokens reach the user instantly using technologies like:
Technology | Use Case |
|---|---|
π¨ Server-Sent Events (SSE) | Most common for AI streaming |
π Streaming HTTP | Simple, efficient token delivery |
π WebSockets | Real-time, two-way applications |
β‘ These technologies ensure tokens appear on screen immediately as they're generated β no waiting for the full response!