A large language model is a transformer trained on enormous amounts of text to predict the next token. That single objective (guess what comes next) turns out to be enough to induce grammar, facts, reasoning patterns, and style, because predicting text well requires modelling the world that produced it.
At inference the model repeatedly samples a next token (shaped by temperature and softmax) and feeds it back in. Its knowledge is frozen at training time, which is why retrieval and tools are bolted on for fresh or private information, and why it can hallucinate.