It literally can't do it in an "in a non-infringing way" as it wasn't made to do it "in a non-infringing way".
People were able to get copy-pasted code verbatim. It means it does not know whether what it does infringe on the GPL or not.
Let say you find a human that never knew anything about copyright and you show him a bunch of Disney movies and you ask him to make you a movie and he literally copy one of their movie. Does it make it non-infringing? (Funny thing is, even people aware of copyrights does infringe it... so yeah hard to say even a machine could make some non-infringing content).
The solution would be to at least make him aware of copyrights and works with that, but first is it even possible, and seconds, is it even enough...
Sadly nothing will ever be done, at least not until it we feed it Disney movies and it start to affect their bottom lines.