What Are Chatbots?
Explore the fundamentals of chatbots including their definition, real-world applications, and evolution from early models like ELIZA to advanced AI chatbots. Learn how rule-based and AI-powered chatbots function differently, and gain hands-on experience by building a simple time-zone chatbot using Python. This lesson lays the groundwork for creating your own conversational AI systems.
Imagine conversing with a machine that understands and responds to you in real-time. That’s a chatbot! In simple terms, a chatbot is a computer program designed to simulate conversation with human users.
Chatbots are versatile, seamlessly integrating into messaging apps, websites, and even your phone’s text messages. They can assist you with ordering pizza, checking the weather, or resolving customer service inquiries. But why are chatbots so important?
Chatbots are revolutionizing how we interact with technology and businesses by offering unmatched convenience. They are available 24/7 to help whenever needed. They boost efficiency by handling multiple conversations simultaneously, reducing users' wait times. Chatbots also provide a personalized experience by remembering user preferences and tailoring responses accordingly. They are a cost-effective solution for businesses, reducing the need for large customer service teams while enhancing customer satisfaction.
Fun fact: Isaac Asimov, the famous science fiction writer, introduced the Three Laws of Robotics in his 1942 short story ‘Runaround.’ While not directly related to chatbots, these laws shaped how people think about human-machine interactions to this day:
A robot may not harm a human or, through inaction, allow a human to come to harm.
A robot must obey human orders unless those orders conflict with the First Law.
A robot must protect its existence as long as such protection does not conflict with the First or Second Laws.
What are chatbots used for?
Chatbots are everywhere, making life easier for both individuals and businesses. Here’s how:
Customer support: They handle routine queries like “Where is my order?” or “What’s your refund policy?” without making users wait for a human agent.
Personal assistants: From scheduling meetings to setting reminders, virtual assistants like Siri and Alexa help organize daily life.
E-commerce and retail: They recommend products, assist in checkout, and even answer questions about sizing or shipping.
Education: Chatbots like ChatGPT or AI tutors answer questions, provide study materials, and engage in interactive learning sessions.
Healthcare: Virtual assistants book appointments, give medication reminders, and support mental health.
A brief history of chatbots
Let’s take a stroll down memory lane and see how chatbots evolved. In 1966, ELIZA was created at MIT as one of the first chatbots. It mimicked a psychotherapist by rephrasing your statements as questions. If you said, “I’m feeling sad,” ELIZA would respond, “Why are you feeling sad?” It was a simple program but groundbreaking for its time, opening up new possibilities in human-computer interaction.
Fast-forward to 1995, and ALICE, which used pattern matching and was more sophisticated than ELIZA, came along. Then, in 2001, we had SmarterChild on AOL Instant Messenger—a chatbot that could chat about various topics and entertained millions of users.
The 2010s marked a major leap forward when chatbots took on a more personalized role in the form of virtual assistants like Siri, Alexa, and Google Assistant. These voice-enabled chatbots brought artificial intelligence into our homes and pockets, making it easier than ever to interact with technology through natural spoken language. They didn’t just respond to commands—they could understand context, learn from interactions, and perform tasks, all while sounding conversational.
But the next revolution came with the advent of Generative AI in the 2020s, driven by technologies like large language models (LLMs). Tools such as OpenAI’s ChatGPT and Google’s Gemini introduced a new class of AI chatbots capable of generating human-like text with remarkable coherence, creativity, and depth. Unlike traditional chatbots, which follow rigid programming or limited training, these AI chatbots can understand nuanced language, answer complex questions, and even create content from scratch, whether it’s writing essays, drafting emails, or even assisting in coding.
This shift toward Generative AI marks the beginning of a new era of truly intelligent chatbots—tools that can learn, adapt, and perform tasks previously unimaginable for machines. As we move forward in this free course, we’ll explore the foundations that make these advanced chatbots possible, laying the groundwork for building your AI-powered conversational systems.
Fun fact: Did you know that ELIZA, the first chatbot, was initially created to demonstrate the superficial nature of communication between humans and machines? Its creator, Joseph Weizenbaum, was surprised to see people emotionally connecting with the chatbot, even though it only mirrored their statements as questions.
How do chatbots work?
Chatbots may seem like magic—machines talking back to us as if they understand every word. But there’s no magic wand behind the scenes, just clever programming and powerful technologies. Let’s break it down into the two main types of chatbots, starting simple and working our way up to the truly intelligent ones.
Rule-based chatbots
Think of rule-based chatbots as the ‘‘choose your own adventure’’ books of the chatbot world. They operate like a flowchart: for every input, there’s a predefined output. If you say “Hi,” it responds with “Hello! How can I help you today?” If you ask, “What’s the weather like?” it might search a database and return today’s forecast. But ask something it hasn’t been programmed for, like “What’s the meaning of life?”, and you’ll likely get, “I don’t understand that”. Let’s say you’re chatting with a pizza bot. Here’s how it might work:
You type: Order a pizza.
Bot replies: What size? Small, medium, or large?
You type: Medium.
Bot replies: What toppings would you like?
Every step follows a rule: your input triggers a specific, preprogrammed response. If you suddenly type “How many calories are in a medium pizza?”, the bot will be no help—it doesn’t have a rule. These chatbots are straightforward to build and highly predictable, making them great for simple tasks. But they have their limits:
They don’t learn: You can ask the same question a hundred times, and they’ll never get better at answering.
They can’t handle ambiguity: If your input is slightly off, like “Med pizza pls”, the bot might not understand.
Rule-based chatbots are like recipe books: excellent at following specific, predefined instructions but completely unhelpful when faced with anything outside their set guidance.
AI-powered chatbots
Now, AI-powered chatbots are the geniuses in the family. They’re like that friend who seems to know a little about everything and can keep up with any topic you throw their way. These chatbots use machine learning and natural language processing (NLP) to analyze what you say and what you mean.
Let’s look at an example:
You ask an AI chatbot, “What’s the weather in Tokyo today?”
The bot doesn’t just match “weather” and “Tokyo” to a database. Instead, it:
Processes the input: It breaks your sentence into parts—“weather,” “Tokyo,” and “today”—and understands their relationships.
Finds the context: It recognizes that “Tokyo” is a city, “weather” refers to a forecast, and “today” means the current day.
Fetches the answer: Using this understanding, it might query a weather API for Tokyo’s current weather.
Generates a natural response: Instead of a robotic “Tokyo weather: 24°C,” it replies, “The weather in Tokyo today is 24°C with clear skies. Don’t forget your sunglasses!”
The genius of AI chatbots is that they can handle ambiguity. Say you ask, “Will I need an umbrella in Tokyo?” An AI-powered chatbot can infer that you’re asking about rain and check the forecast for precipitation. Over time, it might even notice you often ask about Tokyo weather and start offering updates proactively: “Hey, Tokyo’s looking sunny today—perfect for a stroll!”
Educative byte: If rule-based chatbots are like vending machines—good at giving you a candy bar if you press the right button—AI chatbots are more like personal assistants. They don’t just hand over what you ask for; they think ahead, anticipate your needs, and adapt based on the situation. While a vending machine will always give you the same snack, an AI-powered assistant might recommend a healthier option if it notices you’ve been asking for nutritional advice.
How to build a chatbot
Now that we’ve discussed how chatbots work, it’s time to bring that to life by coding a simple chatbot. We will build a chatbot that tells us the current time in different cities. This chatbot takes the name of a city as input and uses predefined rules to adjust the current time based on the city’s time zone. If the city isn’t recognized, it defaults to GMT and informs the user. However, users can exit the program by “exit.’’ Below is the complete code for the basic version of this chatbot:
import datetime
while (True):
## get the name of the city from the user
city = input("Enter city: ")
## get the current time
current_time = datetime.datetime.now()
## save hours, minutes and second of the current time
## in their corresponding variables
hour = current_time.hour
minute = current_time.minute
second = current_time.second
## check for case 1: the learner has typed Boston
if city == "Boston":
hour = hour - 4
## check for case 2: the learner has typed Tokyo
elif city == "Tokyo":
hour = hour + 9
## check for case 3: the learner has typed Chicago
elif city == "Chicago":
hour = hour - 5
## check for case 4: the learner has typed Seattle
elif city == "Seattle":
hour = hour - 7
## check for case 5: the learner has typed exit
elif city == "exit":
break
## if all cases fail, show the time for GMT
else:
print(city, "is not added")
city = "GMT"
# print the name of the city and the its corresponding time
print(city, str(hour) + ":" + str(minute) + ":" + str(second))
Let’s break down the code step-by-step:
Line 1: This imports the
datetimemodule, which is essential for working with dates and times in Python. It allows the program to fetch the current time.Lines 3–5: The
while True:loop creates an infinite loop, ensuring the chatbot continues running until the user types “exit.’’ Inside the loop, on line 5,input("Enter city: ")prompts the user to type the name of a city. This input is stored in the variablecity.Lines 12–14: The current time is retrieved using
datetime.datetime.now()and its hour, minute, and second components are extracted and stored in separate variables (hour,minute,second).Lines 17–30: This defines the chatbot’s logic for handling specific city names If the user inputs
"Boston", the code subtracts4from thehourvariable to adjust for GMT-4. Similarly, for"Tokyo",9hours are added to account for GMT+9, for"Chicago",5hours are subtracted (GMT-5), for"Seattle",7hours are subtracted (GMT-7).Lines 37–39: If the input doesn’t match any predefined cases, the program defaults to GMT. It displays a message indicating that the city isn’t in the database and assigns
"GMT"to thecityvariable.Line 42: The program prints the city name and the corresponding time, formatted as
hour:minute:second. Thestr()function ensures that the numeric values are converted to strings for display.
Now that you’ve built a basic World Clock chatbot, it’s time to expand its functionality by adding more cities. Your task is to add the time zones for cities like London (GMT), Sydney (GMT+10), Mumbai (GMT+5:30), and Cape Town (GMT+2), and incorporate them into your code. Add new elif statements for these cities in the given space on line 23, ensuring accurate time zone adjustments, such as handling Mumbai’s half-hour offset by incrementing minutes and hours appropriately. This task reinforces your understanding of rule-based AI and conditional logic. Also, it challenges you to think critically about edge cases like half-hour time zones.
import datetime
while (True):
city = input("Enter city: ")
current_time = datetime.datetime.now()
hour = current_time.hour
minute = current_time.minute
second = current_time.second
if city == "Boston":
hour = hour - 4
elif city == "Tokyo":
hour = hour + 9
elif city == "Chicago":
hour = hour - 5
elif city == "Seattle":
hour = hour - 7
## add more cities here
elif city == "exit":
break
else:
print(city, "is not added")
city = "GMT"
print(city, str(hour) + ":" + str(minute) + ":" + str(second))
If you’re unsure how to complete the task, don’t worry! You can access the solution by pressing the button below. However, we strongly encourage you to give it a try on your own at least once—it’s the best way to learn and deepen your understanding.