The embeddings on their own are insufficient for this. You need some kind of sequential model to generate the code.
It should be possible to build your own model to do this instead of GPT-4 if you are so inclined. I don't know how the quality would compare but there are various specialized code-specific models already around (and more coming) that work quite well.