You've learned how AI models work, why they hallucinate, how to prompt them, how RAG gives them knowledge and how agents use tools. Now it's time to build something. In this final part you'll make your own AI chatbot, first without any code, then in about 40 lines of Python or JavaScript.
How an AI chatbot works
Every chat app, from ChatGPT to a tiny college project, follows the same loop:
- The user types a message. Your app adds it to the messages list.
- Your app sends the system prompt plus the full messages list to the AI model.
- The model writes the next reply. Your app shows it and adds it to the list.
- Repeat.
See it for yourself. This demo shows exactly what gets sent to the AI on every turn:
🎮 Look inside a chatbot
Pick a message below to start chatting.
What your app sent to the AI on the last turn
// nothing sent yet
Try this: say “Hi! I'm Riya.”, then untick Send chat history and ask “What's my name?”. The bot forgets, because the AI only knows what's in the list you send. Change the personality to see the system prompt at work.
Replies here are scripted so the demo works without an account. The code below connects to a real model.
The system prompt: your bot's personality
The system prompt is where you design your bot. Everything you learned in prompt engineering applies. A good one says:
- Role: “You are StudyBuddy, a tutor for first-year engineering students.”
- Style: “Use simple English and short examples. Keep answers under 120 words.”
- Rules: “Don't just give homework answers; guide the student with hints.”
- Honesty: “If you're not sure, say so.” (Your best defence against hallucinations.)
Option 1: build a chatbot with no code (5 minutes)
Most AI assistants let you create a custom bot right inside the app: in Claude it's a Project, in ChatGPT a custom GPT, and other tools have similar features. The steps are almost identical:
- Create a new Project / custom assistant and give it a name, like “DSA Exam Buddy”.
- Paste your system prompt into the instructions box.
- Upload your notes, syllabus or PDFs as knowledge. Behind the scenes this works like RAG.
- Start chatting, and tweak the instructions until it behaves the way you want.
Option 2: build a chatbot in Python or JavaScript
Coding your own bot lets you put it in a website, an app or a Discord or Telegram bot. You'll need an API key from an AI provider. These examples use Claude through Anthropic's official SDK, and the same structure works with any chat API:
- Create an account on the provider's developer console and generate an API key.
- Save it as an environment variable named
ANTHROPIC_API_KEY, never inside your code. - Install the SDK, copy the code below, and run it.
# StudyBuddy: your first AI chatbot (runs in the terminal)
# 1) pip install anthropic
# 2) Set your key: export ANTHROPIC_API_KEY="your-key" (Windows: setx ANTHROPIC_API_KEY "your-key")
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
SYSTEM = (
"You are StudyBuddy, a friendly tutor for college students. "
"Explain simply with short examples, keep answers under 120 words, "
"and end with one quick question to check understanding."
)
messages = [] # the conversation history: this IS the bot's memory
print("StudyBuddy is ready! Type 'quit' to exit.\n")
while True:
user_text = input("You: ").strip()
if user_text.lower() in {"quit", "exit"}:
break
if not user_text:
continue
messages.append({"role": "user", "content": user_text})
print("\nStudyBuddy: ", end="", flush=True)
with client.beta.messages.stream(
model="claude-opus-5-5",
max_tokens=64000,
system=SYSTEM,
messages=messages,
output_config={"effort": "low"}, # quick, chatty replies
# If the model declines on a safety policy, retry on a fallback model automatically
betas=["server-side-fallback-2026-07-01"],
fallbacks="default",
) as stream:
for text in stream.text_stream: # print the reply as it's written
print(text, end="", flush=True)
final = stream.get_final_message()
if final.stop_reason == "refusal":
print("Sorry, I can't help with that one.")
messages.pop() # drop the question so the chat can carry on
else:
messages.append({"role": "assistant", "content": final.content})
print("\n")What each part does:
SYSTEMis the personality. Change it and you have a completely different bot.messagesis the memory. Each turn adds your message and the bot's reply.streamprints the reply word by word as it's written, like ChatGPT does.- The
refusalcheck handles the rare case where the model declines a request.
Make it better: 5 upgrades
- Add your own knowledge: retrieve passages from your notes before each question (see RAG).
- Give it tools: let it call a function to check the weather, a timetable or a calculator. That's how chatbots become agents.
- Put it on the web: wrap the same loop in a small web app, keeping the API call on your server.
- Trim long chats: very long histories cost more. Summarise or drop old messages after a while.
- Add guardrails: tell it what topics to avoid and test with tricky questions.
Chatbot project ideas for students
Exam revision bot
Paste your syllabus into the system prompt and ask it to quiz you, one question at a time.
Interview practice coach
“Act as an interviewer for a fresher software role. Ask one DSA question, wait, then give feedback.”
Hindi–English explainer
A bot that explains tough English textbook lines in simple Hinglish.
Club or fest FAQ bot
Give it the event details and let it answer the same questions everyone asks.
Coding buddy
Explains error messages from your Python or Java code in plain English.
A finished chatbot project is also a great line on your resume. Put the code on GitHub, without your API key.
You finished the AI course 🎉
From machine learning to building your own chatbot, you now understand how modern AI works, where it fails, and how to use it safely. Head back to the course page to see your progress, or try the DSA course next.
Key takeaways
- ✓A chatbot = system prompt + message history + an API call to an AI model.
- ✓The model remembers nothing; your app sends the whole conversation each time.
- ✓The system prompt sets the bot's role, style, rules and honesty.
- ✓No-code: a Claude Project or custom GPT with instructions and uploaded notes.
- ✓With code: about 40 lines of Python or JavaScript. Keep your API key secret.
Frequently asked questions
Can I build an AI chatbot without coding?
Yes. Most AI assistants, including Claude and ChatGPT, let you create a custom assistant (called a Project, a GPT or similar) by writing instructions and uploading documents, with no code at all. It's the fastest way to make a study helper or FAQ bot for yourself or a small group.
How do AI chatbots remember the conversation?
The AI model itself remembers nothing between requests. Your app keeps a list of all the messages so far and sends the whole list every time. The model reads that history and writes the next reply. If you stop sending the history, the bot “forgets”.
What is a system prompt?
A system prompt is a set of instructions, sent alongside the conversation, that defines how the chatbot should behave: its role, tone, rules and what it should or shouldn't do. For example: “You are a friendly physics tutor. Explain with simple examples and never just give homework answers.”
Which programming language is best for building a chatbot?
Python and JavaScript are the most common choices, and both have official SDKs for the major AI APIs. Python is great for learning and quick scripts; JavaScript is handy if you want to put your chatbot on a website. The concepts (messages, system prompt, API call) are the same in both.
How much does it cost to build an AI chatbot?
A no-code assistant can be free within the limits of an AI app's free plan. Using an API, you pay per token (roughly per word) processed. For a personal project with a few conversations a day, costs are usually very small, but set a spending limit in your API account and keep your API key secret.
🧠 Quick check: build a chatbot
1. How does a chatbot “remember” what you said earlier?
2. What is the system prompt for?
3. Where should you keep your API key?
4. Your bot keeps giving very long answers. What's the simplest fix?
Checking your access…