How to create a chatbot using python

How to create a chatbot using python

In one of my previous articles, I discussed 'How to set up a Python environment and write a “Hello world” program'. I will be focusing on how to create a chatbot using python in this article.

What is a chatbot? A chatbot is an artificial intelligence (AI) software that can simulate humans and computers. It converses or chats with users in a natural language through messaging applications such as a mobile app, websites and telephone.

How does it work?

I. The chatbot gets a user request and tries to identify the user intent and to extract entities.

II. Once the user intent is identified, the chatbot provides an accurate response to the user. However, the response may be in the below categories.

• A contextualised portion of the information • The result of a reaction that the chatbot requires to achieve an interacting interface with one or more backend application Once the context is retrieved, it acknowledges a different output with all the available data stored to give the user adequate response.

Why is it important?

The chatbot is important because it enhances customer experience. It helps to simplify interactions between the clients and services. It also reduces the workload.

Let’s proceed on creating our first chatbot using python.

  1. The first step is to create a folder on your system and name it 'chat_bot'. You can save the folder in your preferred location, e.g. your Desktop.
  2. image.png

  3. Right click on the ‘chat_bot’ folder, and then click on ‘Git Bash Here’ to open the terminal.
  4. image.png

  5. After clicking on ‘Git Bash Here’, you should get the response below:
  6. image.png

  7. Type ‘git init’ then press ‘Enter’, you should get the response below:
  8. image.png

  9. Now that the chat_bot has been initiated, as shown above, type ‘code .’ (Note the space before the period (.) sign inside the git repository. This command automatically opens VSCode on your system. (VSCode can be downloaded from Google if you do not have it installed).
  10. image.png

  11. Once opened, go ahead to create a new file and don’t forget to add the extension e.g. SCA_bot.py
  12. image.png

  13. Initiate a welcome message. For example, (‘Hi. I am SCA’). Once you are done, click on the green icon to run your code as shown on the picture below.
  14. image.png

  15. The response should be as shown below:
  16. image.png

  17. You can add more text of your choice, see sample in the image below for input and output:
  18. image.png I will appreciate your feedback in the comment box.

    See you at the top!