TypeError: text_generation() got an unexpected keyword argument 'token'

I recommend updating the huggingface_hub library to the latest version and using max_new_tokens instead of max_length and huggingfacehub_api_token instead of token.

pip install -U huggingface_hub[hf_xet]

If you really need to use the old version of the code, I think there is a way to downgrade the huggingface_hub library.

pip install huggingface_hub<0.25