Autocomplete, grown up
Your phone suggests the next word as you type. AI chatbots run on a similar idea at an enormous scale.
They were trained on a huge amount of text: books, websites, articles. From it they learned which words tend to follow which, in almost any situation.
When you ask a question, the chatbot writes its answer a small piece at a time, each time choosing what’s most likely to come next.