Chatbots Quiz
Answer these questions to check what you learned about building chatbots.
Quick Review
| Topic | Key idea |
|---|---|
| Rule-based bot | Keywords and fixed replies |
| AI chatbot | A language model writes each reply |
| Messages | system, user and assistant roles |
| Memory | Your code sends the history every time |
| API key | Only on the server, in environment variables |
| Streaming | Text arrives piece by piece, ends with data: [DONE] |
| RAG | Retrieve relevant chunks, then generate |
| Safety | Stay on topic, limit usage, resist prompt injection |
A one-line reminder of how the reply is read from a chat completions response:
Example
const data = { choices: [{ message: { content: "Hello from the AI!" } }] };
console.log(data.choices[0].message.content);Hello from the AI!
And the environment variable rule:
Example
Server code: process.env.AI_API_KEY (correct)
Browser code: "sk-..." written in chat.js (never)Questions
Exercise
Which type of chatbot follows fixed keywords and replies written by a person?
Exercise
Which message role holds the bot's hidden instructions?
Exercise
Why does a chatbot send earlier messages with every request?
Exercise
Which HTTP status from an AI API usually means a wrong or missing API key?
Exercise
In a streamed response, where is the new text in each chunk?
Exercise
What is the main benefit of RAG?
Exercise
Why should the browser's chat code use textContent instead of innerHTML for AI replies?
Exercise
Your API key was pushed to GitHub by mistake. What should you do first?
