When ability means ‘the fact of being able to do something’, it is followed by an infinitive. It is never used in the pattern ‘the ability of doing something’:
✗ Imagination is the ability of making up pictures in your mind.
✓ Imagination is the ability to make up pictures in your mind.
✗ The ability of speaking English has become extremely important.
✓ The ability to speak English has become extremely important.
In this meaning, ability is not used in the plural:
✗ It is good that we have abilities to dream and imagine.
✓ It is good that we have the ability to dream and imagine.
The plural form abilities, which is much less frequent, is used to refer to someone’s ‘skills’ or ‘talents’, and is never followed by an infinitive:
Men and women have different needs, interests and abilities.