Cara menggunakan python chatbot geeksforgeeks

Cara menggunakan python chatbot geeksforgeeks

  • Cari disini...
  • Courses

    • Kategori

    • Web Development

    • Mobile Development

    • Studi Kasus

    • Fundamental

    • Pemula

    • Teknologi Populer

    • Laravel

    • PHP

    • Kotlin

    • Android

    • Javascript

    • Wordpress

    • Database

    • Semua Kelas

    • Flashsale

    • Popular

    • Mentor

    • Roadmap

  • Explore

    • Karir

      Temukan Karirmu

    • Tutorial & Artikel

      Temukan Artikel menarik

    • Podcast

      Podcast seputar pemrograman

    • Webinar

      Ikuti Berbagai Webinar

    • Event

      Temukan Event menarik

    • Beasiswa

      Program Beasiswa

    • Discord

      Komunitas Discord

    • Forum

      Diskusi antar Programmer

    • Leaderboard

      Ranking siswa Codepolitan

  • Partnership

    • For Company

      Solusi tepat untuk perusahaan

    • For School

      Kerjasama untuk sekolah

    • For Campus

      Kerjasama untuk kampus

    • For Mentor

      Peluang penghasilan untuk mentor

LoginRegister

In under 10 minutes

Since tutorials are often easier to follow in real-time.

You may have heard about the hype surrounding AI. Maybe you’re a business leader or an aspiring student. Either way, you’ve probably seen the headlines claiming that ‘AI is on the rise,’ perched at a developmental crest and ready to subsume humans at work. Well, I’ll let you judge that decision for yourself. In this gentle introduction to building an applied chatbot, I show you the basic capabilities that any sensible individual can create, empowered only with tools provided by Dialogflow and Actions on Google.

So, what exactly *is* Dialogflow? The simple answer is this: to help people interact with technology in a more streamlined way. For example, let’s say that I asked my machine, “What coffee shops are open nearby me today?” For more traditional or hard coded systems, if the question wasn’t asked in exactly this manner, then the system would not be able to understand what you were saying. At least in English, there are several ways to convey the same “meaning” with different words…

  • “Is Starbucks open?”
  • “Which coffee shops can I go to, today?”
  • “What cafes take mobile orders?”

We like Dialogflow because it can handle these different end-user experiences. In order to break down this very fundamental understanding of variance in human speech utterances, I’ll (very) briefly review some basic principles behind Dialogflow that will make the rest of the tutorial more accessible, and should provide you with a useful framework for future chatbot interactions.

Now within Dialogflow, we also have entities known as agents. These virtual agents that handle conversations with end users. These get trained, like call center agents, to handle expected conversations.

Agents learn to recognize something known as an intent, which as humans, we naturally understand as something that refers to your motivation, or reason for asking something. Perhaps you’ve listened to somebody ramble and you’re sort of just wondering in the back of your mind “Get to the point!” Well, you’re ultimately able to follow a conversation because you’re constantly assessing a probability of what somebody’s intent is during a conversation. Likewise, an intent is used to help your virtual agent take a phrase and understand what the user, or speaker, wants to get out of the conversation and then inform the agent’s final response.

So with the cafe example, the intent could be described as a “Find Cafe Intent.” Before you can even order Starbucks, the agent needs to know where to find a cafe, so we ask for your zip code in the first pass. Equipped with this intent, our agent then knows what kind of parameters to listen for, what kind of data that it needs to extract, and what kind of answers or responses the agent should give your end user. Some example responses might be:

  • “Sure, Starbucks is open 0.1 miles from you.”
  • “The Philz Coffee within 2 km from you is closed.”

Finally, within each intent, we can define Entities, that identify key pieces of data from a user’s utterance that we should extract. Conceptually, these are like objects that the agent should look for in the conversation — such as “date” or “location.” Perhaps the entity types are even more customized, like a “coffee’ entity that matches different types of coffee (americano, mocha, iced latte) that may be available for purchase with our caffe agent.

Before we get into the process, the final component to consider is a Dialogflow Context. Just as how context matters in normal conversations, Dialogflow agents need to understand the context, in order to match the intent. For example, if you just randomly walked up to somebody on a sidewalk and said, “Ok let’s order a mocha!”, then you would be likely to receive a bewildered stare and this humble stranger would probably say something along the lines of “Um, who are you?”

However, if you set the context by first asking the same stranger, “Hey, what coffee shops are open nearby me?”, then you set a ‘Cafe-Shopping Context.’ Therefore, this previously bewildered stranger might respond more normally if you followed up with “Could I order a mocha?”

The last ‘foundation’ that you should understand for building Chatbots using Google Assistant is an Action. Just as the name implies, an action can be the first entry point to initiate an interaction with your assistant. This is like when we start a conversation with “Hi Dr. Starbucks!” in order to activate our Starbucks chatbot. However, even more broadly defined, an Action enables the fulfillment or execution of some user-defined intent, through some service, app, or logic.

If you’ve got any more questions, feel free to reach out to me directly or check out the YouTube video. In the meantime, let’s get our hands dirty!

Cara menggunakan python chatbot geeksforgeeks

A screenshot of your beginning page.
  1. First, you want to visit: https://console.actions.google.com/u/0/

2. From here, you click on “New Project’ in order to identify a tentative “project name.” We’re going to customize it, and you can click on the button that says “Conversation.” Remember, I’m doing this on June 30, 2020, so it’s possible that the interface has changed again. But for those of you watching this in a timely manner, I hope this helps pique your interest. Now, scroll down to the bottom and make sure to Define an action in Dialogflow.

Cara menggunakan python chatbot geeksforgeeks

“Click here to build your Action using Dialogflow” will be located at the bottom of the Custom menu.

3. Next, click on “Decide how your action is invoked. You’ll then see settings, and a display name. This is the name that we use to trigger our agent and activate him or her. We’re going to call our agent, Agent S for Starbucks. A nice, gender neutral name. Make sure to save it.

4. You’ll then be able to specify Actions. Click on Get Started. This will open up a series of windows that will ultimately take you to Dialogflow, and the loading process at this step will require You may have to authorize your Gmail to login to Dialogflow.

Cara menggunakan python chatbot geeksforgeeks

The “Actions” button is to the left, under “Invocations.” Under Create Action, clicking “Build,” should lead you to Dialogflow if prior instructions were followed accurately.

5. From here, you should then be brought to the “intents” page in Dialogflow. Now we can start building our Starbuck agent’s intent. Choose a name for the corresponding Dialogflow and confirm your settings before proceeding.

Cara menggunakan python chatbot geeksforgeeks

Your default dialogflow page that you are directed to should resemble this page.

6. So we’re #blessed because we have access to a default welcome intent conversation. That’s great. And we’re going to throw it all away! Find these training phrases and just kill it all by clicking on the trashcan icon that should appear at the right of the text string.

7. Now, let’s change up the responses to become customized to our first question that our agent will be asking. We’re going to fill our first “welcome, hello” intent with a request to geolocate Starbucks near you. Fill out this section with questions like “Where do you live?” Or “Let’s get you Starbucks. First, what is your zip code?” After you provide enough training phrases, click SAVE. Click the blue button at the top, and you should see at the bottom right of your screen, an “intent saved” notification pop up.

Cara menggunakan python chatbot geeksforgeeks

An example of responses to request.

8. Now, here’s a good practice. Before we make the system any more complicated, let’s test this first component. Does it work? Do you extend pipes if they’re already leaking? Probably not. So, let’s shift gears for just a minute. Let’s go back to the left sidebar in Dialogflow, and click on Integrations. Then, click on Google Assistant, Integration Settings.

Cara menggunakan python chatbot geeksforgeeks

Click on “Integration Settings” in the primary Google Assistant button in order to get to this screen.

9. From here, you need to click Test. This loads our actions into the Actions console simulator. There’s some cool stuff here, which is courtesy of the amazing Google developers community who put this together, and out of scope in this video.

Cara menggunakan python chatbot geeksforgeeks

To get to this point, I clicked on “Talk to Dr. Starbucks,” as my main invocation, which appeared where you now see “Cancel.”

10. So naturally, we want to build on our previous conversation, so we’re going to create a new intent. And of course, the training phrases to trigger this intent have to be the responses we anticipated in the previous one. So if I’m asking for a zip code, let’s feed the system some possible zip codes Make sense, right? Let’s go back to dialog-flow. Then we will click on Intent, and HOVER our mouse over Default Welcome Intent. From here, we will then create another intent, and fill out the following fields.

Cara menggunakan python chatbot geeksforgeeks

When you hover over the Default Welcome Intent, the text on the right will appear, providing you with the option to “Add a follow up intent.” Here, we can create our “GatherData intent.

11. It’s important to remember that we’re using this intent to collect information. Notice how I fill out the data and make it all required, for specifically ’size,” “drink” and “temp.” If you order from Starbucks, they always ask this. You’re welcome to get creative here, just make sure to create realistic prompts that identify and specify what parameters your agent needs to gather for a good Starbucks order. An example is shown below.

Cara menggunakan python chatbot geeksforgeeks

In our follow-up intent, notice that logically, the “training phrases” to activate this intent contain the answers to the “response questions” posed by the prior intent: “What is your zip code?”

Cara menggunakan python chatbot geeksforgeeks

Under Action and parameters, you may specify the textual prompts that the agent will use to retrieve the desired entity value. In this case, $drink

12. The final step is to have your Starbucks agent indicate the parameters of your order and review it. For example, “Did you order a grande, iced caramel macchiato?” After you have successfully taught your agent how to provide this type of response, we can end the conversation.

Cara menggunakan python chatbot geeksforgeeks

Notice that entity parameters identified earlier may be referenced in the text response.

From this point, you’ll now have a chance to test out your own chatbot within the Google Assistant test platform. Of course, this is a very basic, introductory version of an “Order Starbucks” chatbot that does not actually access any Firebase database, which would be a closer real-world application. If you’re interested in learning how to do this, then let me know! Likewise, if you’ve made it to the end of this article, then I hope that this brief tutorial has made chatbots a little less mysterious. Even better, if I’ve inspired you to begin traveling down the rabbit-hole of artificial intelligence, and build your own chatbot!

Cara menggunakan python chatbot geeksforgeeks

Find me on Insta/Twitter: @seanbatir. Learn more at https://youtube.com/seanbatir PC: Mikita Zhur