In order to understand ChatGPT and LLM, read my blog post about generating autocomplete hints using Markov chains.
( That blog post was later copypasted to my untitled/unsorted collection of math notes. )
LLM works by the same principle, but orders of magnitude more complex and advanced, of course.
Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.