If I were to quote a couple of words from a song in a book, I'd need to ask permission and, depending on the whims of the copyright holder, pay a fee or some sort of royalties (or, of course, have the request denied).
With this in mind, is it not logical that an "AI" that absorbs huge swathes of code and regurgitates parts of that on demand also respect the rights of the authors and the licence obligations of the code it has read?