Implementation of the chat function