Generate a function in Python to count the number of words in a given sentence.
Hello there
def count_words(sentence):
    words = sentence.split(' ')
    return len(words)

print(count_words("Hello there")) # Output: 2