How much theory do you know? That would be a great start, to learn chord structure, inversions, etc....

Now if you are asking how do they come up with lines that are counter to the melody, like with lyrics that are not what the melody singer did or singing along with the melody, that is going to come from your creativity alone.

You can also buy hardware known as a Vocoder that will sing the notes that you play into it while you sing. I use one of those. They are everywhere on the internet.