Category: Chat

  • How to build your own chatbot

    With a touch of Huggingface and Cloud run

    The use of chatbots has increased drastically in recent years and almost all major companies use some form of chatbot in their business, and it is not hard to understand why this is the case. Since BERT was delivered by google, the performance of NLP models has seen impressive progress. The latest state-of-the-art model GPT-3 has a breathtaking 175 billion parameters in its model, which makes interactions with the model almost indistinguishable from a human being.

    So in this article I would like to demonstrate how to build your own chatbot and have it wrapped as an API service.

    The project is divided into two parts. First we need to have a trained chat model that can make predictions, then a server that can handle requests to our model.

    There are several models available that can be used to build a chatbot. We will use blenderbot, created by facebook’s research team in 2019. The model is an open ended chatbot, which means that it is not created to handle certain given actions in the backend, which is the more common use case for businesses. Instead this model is only focused on imitating human communication.

    We will use a small implementation of the model with no additional fine tuning. However this is heavily desirable for a more sophisticated chatbot.

    We start by creating a file that we will use to download the model. To help us, we use Huggingface, a python library that provides various high quality NLP models.

    Then we create a python class that we will use to handle the logic from converting our english text to create our word tokens that we will use as inputs for our model.

    We then build a Flask API with two endpoints, one for checking if the service is working and one for integrating with our chatbot.

    Finally we generate a Dockerfile that when being built will pre-download the chat model so that when we send request to our API it can make quick responses, instead of reloading the model every single time. This will drastically improve the performance of our bot. To host the API we use gunicorn as our wsgi server with no additional web server framework.

    From our local machine to production

    The steps from running your model on your local machine to have it running in production can see daunting. However several services have done this step a lot easier in recent years.

    We are going to work with google cloud run for this project. Googles “serverless” platform, I don’t like the word serverless since of course there has to be a server running the code, but it is serverless in the sense that it doesn’t save any client data from session to another session and that we get whatever server is available at any given time.

    Trending Bot Articles:

    1. Chatbot Trends Report 2021

    2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model

    3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen

    4. An expert system: Conversational AI Vs Chatbots

    In order to run our code on google cloud run we have to provide it with our docker image that we will create with the build command. Make sure to execute the command in the same folder where the Dockerfile is located.

    docker build -t <docker_name> .

    Next we need to push our image to google container registry. This could be done directly in the web GUI or as we will do here, via the gcloud SDK.

    gcloud builds submit --tag gcr.io/<PROJECT-ID>/<docker_name>

    Now, we are almost ready to go. The last step is to create our cloud run service, which again could be done with either the GUI or the cloud SDK. Here we specify that we want two cpu with 4G ram in each container running our docker image.

    cloudrun_example$ gcloud run deploy chatbot 
    --image=gcr.io/$PROJECT_ID/chatbot:latest
    --platform=managed
    --concurrency=1
    --set-env-vars=MKL_NUM_THREADS=2,OMP_NUM_THREADS=2,NUMEXPR_NUM_THREADS=2
    --cpu=2
    --memory=4G
    --allow-unauthenticated

    If you set it up correctly you will receive an URL with the address to your service. Like the one below for our chatbot.

    https://chatbot-5vvmts3sdf-lz.a.run.app/

    Now, let’s try sending a CURL request to our chatbot.

    Hi, how are you?

    curl --location --request POST 'https://chatbot-5vvmts3sdf-lz.a.run.app/query' 
    -H 'Content-Type: application/json' 
    --data-raw '{"lastConversations": ["Hi, how are you?"]}'

    {“botResponse”: “i’m good. just got back from a long day at work. how are you?”}

    There we go!

    We managed to create a high performance general purpose chatbot with an associated API.

    Full code can be found here:

    Resources:

    https://huggingface.co/transformers/model_doc/blenderbot.html

    A state-of-the-art open source chatbot

    Don’t forget to give us your 👏 !


    How to build your own chatbot was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.

  • Chat bot to add all occurrences of a string.

    I am wanting to write a simple chatbot that polls a chat and adds up all occurrences of a string at the end of the day and displays how many it was.

    Example. Chat bot monitors a chat thread, check every so often for new occurrences of X and adds its to the running total. at the end of the day lets say midnight is writes a message the number of times X was mentioned that day.

    I dont really know where to start with this however I am a computer engineer and very tech savy. any insight would be great.

    submitted by /u/GrandWizardZippy
    [link] [comments]

  • Library Telegram Bot

    Here we will create a telegram bot which will send random book of given genre to user.

    We will use an open source project “draw your bot” (https://github.com/Tsitko/drawyourbot) to generate a bot. It allows to draw a bot structure in draw.io instead of coding it.

    So we need to clone drawyourbot project and install its requirements (the instructions of how to install requirements are here: https://github.com/Tsitko/drawyourbot#install-requirements).

    And we also need to register our bot in telegram (the instruction is here: https://core.telegram.org/bots#6-botfather)

    As we have a project we need a library (books sorted by genre). For this bot I will use a very small library like that:

    Project and library structure

    And we also need a function which will get one of those book so we could send it to user. Here is that function code (you should put it into bots directory to the file book_funcs.py):

    Trending Bot Articles:

    1. Chatbot Trends Report 2021

    2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model

    3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen

    4. An expert system: Conversational AI Vs Chatbots

    And the only thing left is todraw a bot structure:

    bot structure in drawio

    You need to change bot_token to your bots token and if you are using your own function, you need to change _functions_book_funcs::find_book(genre) to your own function.

    And as you are done, you need just to generate a bot (instructions: https://github.com/Tsitko/drawyourbot#generating-bot-code).

    And you have a bot which you can run and test:

    Don’t forget to give us your 👏 !


    Library Telegram Bot was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.

  • How Chatbot’s Voice Commerce Revolutionizing Live Commerce

    In the neck-throat competition of the e-commerce industry, the business offering the best and time-savvy customer support often wins the race. It is precisely why the customer support sector has seen such a wide range of innovations in recent years.

    And even though you may feel that your e-commerce venture is foolproof, there’s always scope for improvements and refinement. The defining part of any business is how available are your services or products for the customer if they require your assistance.

    Employing a dedicated person delivering 24×7 customer service is unrealistic and expensive. That’s where chatbots solve the problem and take care of consumer needs round the clock.

    As is the rule of any conversation, chatbots are a two-way thing — that offers benefits for both brands and users. Chatbot help in interacting with new, current, and future consumers channeling them into the sales funnel without directly interacting with them. You get to send personal messages without actually hiring a dedicated person for the job.

    So what are chatbots?

    Chatbots are pre-programmed software bots that interact with customers via an automated chat interface and carefully scripted conversations. Interacting with a chatbot is like talking to real-life customer support as you get prompt replies to queries or feedback.

    And though they can be deployed for different purposes, they are primarily used in customer service-related settings. However, there’s a razor’s edge difference between a fully automated chatbot and a semi-automated chatbot as they are categorized into –

    1. Decision tree or rule-based chatbots — These Chatbots work according to a predefined set of rules fed into them beforehand. They are designed like flowcharts delivering readymade responses to problems. Rule-based chatbots are not capable of answering outside the domain of predefined rules. It is because they answer only according to the set-ups you train them for.
    2. AI or NLP (natural language processing) based chatbots — These are ML (machine learning) enabled chatbots that offer interactions just like we humans do. They respond mindfully, extracting meaning and context from previous interactions and specific phrases to provide suitable responses. NLP and ML let them learn from every interaction, enhancing their performance with every response.
    3. Multi-linguistic Chatbots — Using a combination of NLP and ML, this bot can interact within their language. Bots with this feature are capable of switching languages according to consumer’s utterances.

    Trending Bot Articles:

    1. Chatbot Trends Report 2021

    2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model

    3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen

    4. An expert system: Conversational AI Vs Chatbots

    Decoding the link: Live Commerce & Chatbots

    Live commerce is a product of two ingredients — e-commerce and live streaming. In other words, when you market products live through e-commerce platforms utilizing real-time interaction between buyers and sellers, that is called live commerce.

    The concept first originated in China, where products were promoted and sold by influencers on their social media platforms. Live streaming emerged as an alternative for businesses to transport surplus inventory, spreading their reach, especially for small and local enterprises under prevailing pandemic conditions.

    How chatbots overhauled e-commerce?

    Cutting-edge technologies like ML and AI have marked their presence in almost every aspect of human lives. So why leave customer care untouched. Gartner had predicted that by the year 2020, more than 80 percent of client interaction in the e-commerce business would be managed using AI, which became evident.

    Today, chatbots are extremely popular in the e-commerce industry, but why let’s find out:-

    1. Surge in the use of online messaging platforms — Did you know approximately 63 percent of consumers are of the opinion of letting businesses run on messenger. That is why online messaging platforms like WhatsApp, Telegram, and Facebook Messenger etc. have become instant hit amongst people. Deploying Chatbots on these apps can prove to be a potent medium in helping consumers regardless of their presence on online portals.

    2. Dedicated support and cuts waiting time — Chatbots efficiently manoeuvre that task of giving personalized attention to every customer delivering uninterrupted customer support. They also reduce time wasted by consumers in waiting for an appropriate response.

    A survey states that roughly 40 percent of customers of all age groups favour using chatbots for online shopping. They offer instant support, available round the clock and provide complete satisfaction to clients. And 64 percent of users online find 24-hour service to be the best feature of Chatbots.

    3. Help in resuming of shopping — When people shop online they often compare several brands, and might not finalize a purchase early. Moreover, there are going to be lot of queries and page visits that may not get converted into successful deals.

    Using a conversational chatbot, you get an opportunity to get those buyers back and finalize shopping. Personalized messages can be sent via chatbot giving product recommendations, similar products, discounts and offers etc. This gives you an opportunity to build profits and earn money from a deal as good as lost.

    4. Minimizing operational overheads — The money and manpower that you would have invested in employing a customer support executives is reduced by using a single software agent for your business. Chatbots are said to reduce operational cost by up to 30 percent.

    5. Product Notifications — Sending suggestion and recommendations through mails and other means becomes somewhat repetitive and uninteresting. Instead brands can utilize chatbots for advertising products in real-time which seem more appealing and conversational.

    6. Order Processing and tracking — Customers can even make online purchases through bots and check information about their product without visiting the site directly. They can even track their purchase using a bot without having to call a customer executive or posting a query online

    7. Holiday Promotions — Remember ecommerce bots work on ML and AI. Therefore they learn and keep track of your queries and suggestions. This way they help buyers look for specific products more easily.

    Bots in travel sites work in this manner, they look for destinations and sites entered by you. They even compare prices, checks reviews and offer the best decision. They can be deployed for delivering offers and discounts and even promote holiday packages.

    8. Choosing the best chatbot — There are lot of options available while choosing a right chatbot for your venture. It is always recommended to make final selection after proper research and analysing the requirements. The following points should be kept in mind before coming to any conclusion

    • Information repository — If you want your chatbot to work as a self-sufficient tool then it should have a rich repository of knowledge. The repository should be well framed and should have scope for all scenarios. If you can assimilate the information repository with your chatbot, this can prove to be good solution.

    Third-party integrations — To enable your chatbot to process business automation smoothly and resolve recurring issues, it needs third-party integration with different applications like inventory management, CRM, software management, etc.

    • Code free bot builder — An intelligent code free bot builder is the best option to develop bot workflows. A ready to use bot builder is basically multiple nested if-then-else conditions which try covering all scenarios.
    • Detailed analysis — A good reporting mechanism and analytics are required for Chatbot optimization. A typical Chatbot solution will give detailed analysis along with reports that can be utilized for measuring performance.

    9. Optimising social media marketing and other channels — Already crossing the mark of 3.5 billion user mark, social media is now one of the most powerful digital marketing tools. By integrating chatbots to your social media and other channel marketing strategies you can just imagine the impact it can create for your business and brand.

    Future looks bright for Live Commerce with chatbots

    Live streaming e-commerce is a rapidly growing industry. Statistics reveal the annual growth has reached nearly $60 billion. Successful deals obtained via live commerce reach about 100 percent mark in 2020 unlike 2019 which was almost 9 percent of total sales online.

    Chatbots significantly alter how businesses are done, be it engaging customers, handling campaigns, converting sales, lead generation, or payment automation.

    The future of chatbots is intensely moving towards payment automation and allowing consumers to make payments directly over live chat or messenger apps.

    Recently, MasterCard launched a chatbot, especially for customer payments, to answer account-related queries, assist customers in setting payment alerts, and collecting final payments from customers.

    Live e-commerce and interactive commerce are the future of the retail industry. The chatbots are forecasted to double this impact every year to a whopping $112 billion by 2023. And businesses that have invested in conversational commerce early witnessed a steep rise in profits, deal conversions, and optimizing resources.

    Don’t forget to give us your 👏 !


    How Chatbot’s Voice Commerce Revolutionizing Live Commerce was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.

  • Support Telegram Bot For Github Project

    Here we will build a support telegram bot which will search users question keywords in your Readme.md and will send a link to the most relevant part of your md to the user.

    We will use an open source project “draw your bot” (https://github.com/Tsitko/drawyourbot) to generate a bot. It allows to draw a bot structure in draw.io instead of coding it.

    So we need to clone drawyourbot project and install its requirements (the instructions of how to install requirements are here: https://github.com/Tsitko/drawyourbot#install-requirements).

    And we also need to register our bot in telegram (the instruction is here: https://core.telegram.org/bots#6-botfather)

    To search in Readme.md we will use a function from draw your bot standardfucs (https://github.com/Tsitko/drawyourbot#search_md). But you can use your own function (just code that function, add and add a .py file with that function to ‘bots’ folder).

    And as we have a draw your bot project and a function to search in md file, we only need to draw our bot structure in draw.io:

    drawio source: https://github.com/Tsitko/drawyourbot/blob/main/examples/support_md.drawio

    You need to change bot_token to your bots token and if you are using your own function, you need to change _functions_standardfuncs::search_md(query, “https://github.com/Tsitko/drawyourbot/blob/main/README.md”) to your own function.

    If you are ok to use the standard search_md function, you just need to change https://github.com/Tsitko/drawyourbot/blob/main/README.md to the link to your projects md.

    So the bot will just ask the user what he/she is looking for and will get the user’s answer. After that it will find a link to the part of your Readme.md which is the most relevant to the user (if it will not find such a part it will return a link to Readme.md start line). And in the end it will ask the user to push /start command if he wants to search again. The /start command is to start from the first message (what are you looking for?).

    Trending Bot Articles:

    1. Chatbot Trends Report 2021

    2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model

    3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen

    4. An expert system: Conversational AI Vs Chatbots

    And as you are done, you need just to generate a bot (instructions: https://github.com/Tsitko/drawyourbot#generating-bot-code).

    And you have a bot which you can run and test:

    Don’t forget to give us your 👏 !


    Support Telegram Bot For Github Project was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.

  • How to use custom logic with Chatbot frameworks

    I am working on a Chatbot, I have implemented it with Dialogflow (Dialogflow ES). I found that Dialogflow has the following Pros

    • Easy to use
    • Good at Intent classification
    • Good at extracting Entities (prebuilt/custom)
    • Conversations can be chained to a certain extent using input/output contexts and lifespan
    • Less flexible

    But in my use case, there are certain situations where human level judgment is required and it cannot be done using Dialogflow. Can we add our custom logic to process certain user requests in Dialogflow or any other Chatbot framework which provide more flexibility

    submitted by /u/arush1836
    [link] [comments]