How to generate the words in the specified candidate words?

I’m working on a task to generate the next word. I read your tutorials and documentation on text generation, but didn’t find how to specify candidate words.
related docs:

For example, text=“I love”, candidate words=[“you”, “money”, “her”],I want the next word to be one of the words in the list. Any ideq?