How to use GPT-2 as a chatbot

I am trying to write a Python script so I can chat with GPT-2 as if it was a chatbot. So far it’s not very successful. It doesn’t take into account the conversation and has a lot of errors. I will attach the code. Only pay attention to act_gpt(). ac-gpt is literally just my copy of gpt-2. Does anyone think they might be able to help?

Keep in mind I also don’t know that much about Hugging Face or Python and primarily use Java. Most of the ac-gpt() function was ported from a Java project which used the OpenAI Java library.

Code: AC-GPT Python Script