Chatgpt works by predicting the next word in a sentence that is a response to some query. These predictions are based on a large language model, itself the result of prior analysis of millions of texts, harvested from the internet.