← BUILD YOUR FIRST AI APP IN 10 DAYS
DAY 3 OF 10
3-4 hours 3 GOALS

Day 3 of 10

Wire In a Brain

Build a real chatbot with personality and memory. The infrastructure every AI product in the world runs on.

TODAY'S GOALS

Yesterday you made a single call and watched the model answer. One question, one response, done.

That is not how real products work. Real products remember what you said. They have a personality. They build context across turns. Today you build that: a chatbot with a voice and a memory, running in your Colab notebook.

This is the infrastructure every AI chat product in the world is built on. ChatGPT, Claude, Gemini. Strip them down and they are all running this same pattern.

The System Prompt Is the Product

Before your message arrives, the system prompt runs. It shapes everything the model says, how it says it, what it refuses to do. Think of it as the contract you write with the model in plain English.

Run the same question with and without one:

from groq import Groq
from google.colab import userdata

client = Groq(api_key=userdata.get('GROQ_API_KEY'))

# Without a system prompt
response = client.chat.completions.create(
    model="llama-3.3-70b-versatile",
    messages=[{"role": "user", "content": "Explain recursion."}]
)
print("WITHOUT SYSTEM PROMPT:")
print(response.choices[0].message.content)
print("\n" + "="*50 + "\n")

# With a sharp system prompt
response = client.chat.completions.create(
    model="llama-3.3-70b-versatile",
    messages=[
        {
            "role": "system",
            "content": """You are a sharp teacher who explains technical concepts to curious beginners.
Rules: one vivid analogy per explanation. No jargon without definition. Under 100 words unless asked for more.
Never say "Great question!" or any filler. Just teach."""
        },
        {"role": "user", "content": "Explain recursion."}
    ]
)
print("WITH SYSTEM PROMPT:")
print(response.choices[0].message.content)

Run this. The difference is not subtle. The system prompt is the most powerful variable you control in any LLM application.

Memory: You Are the Historian

The model remembers nothing between calls. Every request is stateless. But you can give it memory: just send the full conversation history with every request.

The pattern is three lines of logic that repeat every turn:

# 1. Append what the user said
messages.append({"role": "user", "content": user_input})

# 2. Call the model with the full history
response = client.chat.completions.create(...)

# 3. Append what the model said
messages.append({"role": "assistant", "content": reply})

The model reads the entire messages list on every call. Its “memory” is just the history you manage.

Build the Chatbot

from groq import Groq
from google.colab import userdata

client = Groq(api_key=userdata.get('GROQ_API_KEY'))

SYSTEM = """You are a learning companion for someone building their first AI project.
You celebrate progress without sugarcoating. You clarify without simplifying.
When someone asks something basic, you treat it with the same respect as a hard question.
You never say "Certainly!" or pad your responses. You just answer.
Keep it conversational. Under 150 words unless the question genuinely needs more."""

def chat(messages, user_message):
    messages.append({"role": "user", "content": user_message})

    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[{"role": "system", "content": SYSTEM}] + messages
    )

    reply = response.choices[0].message.content
    messages.append({"role": "assistant", "content": reply})
    return reply

# Run a conversation
conversation = []

turns = [
    "I just made my first API call. What exactly did I just do?",
    "So the model has no memory at all between calls?",
    "Then how does it know what I said earlier in this conversation?",
]

for question in turns:
    print(f"You: {question}")
    reply = chat(conversation, question)
    print(f"Assistant: {reply}\n")

Run this and read the third answer carefully. The model references the first question because you sent the full history. You built that continuity. Not the model.

Make It Yours

The system prompt above is mine. Write your own.

Pick a domain you know or are learning: finance, fitness, cooking, a specific programming language, a subject from your degree. Write a system prompt that makes the chatbot an expert in that domain. Include:

  • What it is and what it knows
  • How it should respond (tone, length, format)
  • At least one thing it should not do

Then have a real conversation with it. Ask it something hard in that domain. See if it holds the persona.

Share the notebook link. It is your first proof of work.

The Infrastructure Is Yours Now

The chat interface you have used for years? It is this. A messages list, a system prompt at the top, a model call in the loop, history appended on every turn.

The difference between you now and you three days ago isn’t exposure to the technology. It’s ownership of it.