Basically, ChatGPT is a prediction algorithm. It does not search the internet for the reply. It predicts the word that shall come next in the sentence based on the previous words. And for this it would have been trained on various articles taken from the internet.