Chatbots and Watson: Let’s talk about national parks

Chatbots and Watson: Let’s talk about national parks

Course Features

Course Details

Just a walk in the park! In this course, create your own chatbot using the IBM Watson Conversation service. Your chatbot will simulate a conversation around some of the coolest US national parks, such as Arches and Yellowstone. You’ll learn to train your bot, create its dialog, and write code to integrate with external APIs. Want to know what the weather will be like in Denali? Who wouldn’t? You’ll integrate the IBM Weather Company Data service into your chatbot. With the IBM® Watson™ Conversation service, you can create an application that understands natural-language input and uses machine learning to respond to users in a way that simulates a conversation between humans. Watson Conversation uses concepts like intents, entities, and dialog to help you craft powerful conversational experiences. You’ll learn about these concepts and how to apply them by building a chatbot. You’ll also learn how to create conversations declaratively (without code) and programmatically by using the Watson Conversation tooling and Watson Developer Cloud SDK.
Interact with the working version of the national parks application below and try these phrases:
  • “Tell me about animals in Denali”
  • “Tell me about Zion National Park”
You can also ask “What can you do?” to see a set of options.
Get started

Lab 1: create a Watson Conversation instance Intents Lab 2: import and create intents

Entities Lab 3: import and create entities

Dialog Lab 4: create a dialog flow (conversation)

FREE
Create a workspace
2 of 7
From the Watson Conversation tooling, open the conversation workspace, and click Create. Name the workspace national-parks-example, and then click Create. Click the Dialog tab, then click the Create button. The Watson tooling provides a “Conversation starts” virtual node and the first child node. In the Triggered by field, enter conversation_start. This condition is invoked on the start of a conversation. In the Fulfill with a response field, add the following response: What national park would you like to know about? Note that the Conversation tooling automatically adds a new node with condition anything_else. This node is evaluated last and can be used as a failover when no previous node conditions match. To create a failover message, enter a response to the node with condition anything_else: I didn't understand that. Test the dialog that you’ve created so far by clicking the Chat icon. When you open the chat, you see the first conversation_start node with a response of What national park would you like to know about? Enter How about Yosemite? Notice that Watson doesn’t understand that intent and therefore fails over to the anything_else node for its response. Add some variation to your responses. Start with the conversation_start node. Click Create another response and enter an additional response variant: I'm here to provide information about national parks. What park are you interested in? Click Create another response > Set to random to enable Watson to randomly choose one of the responses. Select the anything_else node, and modify the first response to I didn't understand that. Ask me about a national park…. Add another response variant: Sorry I'm only trained on national parks. What park would you like to know about? Click Create another response > Set to sequential. To test the dialog, open the Chat pane. Click Clear to restart the conversation. Do this multiple times, and observe that the prompts are shown at random. Enter an utterance to test the anything_else node. For example, enter I'd like to know about Yosemite. Notice that the responses are shown in sequence. First, you see the...

Continue Reading
FREE
Add context variables
4 of 7
Context variables help you speed up the process of providing responses by allowing you to reuse the names of things, such as the names of the national parks. For example, you’ve created responses that include the names of the parks. However, if you add or remove park names, you don’t want to be forced to update every response that you’ve created. With context variables, you can make this update one time. Click the Edit (pencil) icon to open the conversation_start node. Open the Advanced editor (click the icon with curly brackets surrounding an ellipsis). In this editor, you see a JSON representation of the response that you created in the graphical user interface. Enter the following code to create the context variable:  }, "context":{ "parks":["Yellowstone", "Yosemite", "Arches"] } } To test your change, open the Chrome Developer tools. Click the Network tab and clear the conversation. Note that this action invokes the conversation API’s message endpoint with a payload that resets the conversation. This means that the conversation_start node, which contains your context variable, was invoked. By previewing the response, you should see your context variable is now included in Watson’s response. Close the Advanced editor and open the #listparks node for editing. In the Chat pane, enter list the parks. You see the response of I can tell you about Yosemite, Yellowstone, and Arches. These are not the parks you added to context. To update the response to use the values from your context variable, remove the text Yosemite, Yellowstone, and Arches from the #listparks node, and replace the text with $parks. Note: The dollar sign specifies a context variable. Go to the Chat pane to test the conversation. Clear the conversation to reset it. Enter the text list parks. You now see the output. The formatting is poor, but you’ll fix this in the next section.

Jump to action Watson Developer Cloud SDK Lab 5: interact with the app programmatically

Lab 6: enhance the sample application

FREE
Lab 6 overview
2 of 6
Use all that you have learned so far to enhance the national parks sample application. The application provides a conversational experience that enables users to ask questions about national parks in natural language. The sample application uses the Watson Conversation service to understand the user’s input and respond with answers that include both text and images. The system can answer questions and statements such as: Example 1 User: Tell me about Mount Zion National Park. Watson: <answer> User: What animals live there? Watson: <answer> Example 2 User: Can you describe the plant life? Watson: For which national park? User: Denali Watson: <answer> To complete your national parks application, follow these main steps: Modify the server code to dynamically provide the list of known national parks through the conversation context. To do this, you will create a parks context variable that contains a list of known parks. The known parks are Mount Zion, Denali, and Great Smoky Mountains. Create a park context variable that will track the current park name that the user is interested in. This enables the application to answer questions about parks that were referenced earlier that perhaps are not mentioned in the user’s most recent question; for example, “what animals live there?” Use the ParksDatabase module to look up national parks by name and provide a park’s data object as part of the Watson Conversation response. Use the Watson Conversation tooling to alter the conversation and its dialog flow. You will enhance the application so that it can answer questions about the plant life at each national park. See the working version of the national parks application. Prerequisites Complete all previous labs and watch all videos for this course so that you have the following software, accounts, and applications ready to go: Node.js and npm Git Bluemix account An instance of the Watson Conversation service...

Continue Reading
FREE
Clone the source code repository and run it
3 of 6
Clone the source code by using the .branch project-skeleton. git clone –b project-skeleton https://github.com/cdimascio/nationalparks_conversation cd nationalparks_conversation nationalparks_conversation as the project root. Tip: To see the compete working code, switch to the master branch by running the following command: git checkout master. Run git checkout project-skeleton to switch back. Import the conversation to Watson Conversation tooling. Click the Import button to import the workspace file located in the project root at resources/conversation_workspace.json. This file is located in the repository that you cloned in step 1. If you haven’t done so already, record your workspace ID from the Watson Conversation tooling page. If you haven’t done so already, record your service credentials (username and password) from the Service Credentials page. Be sure that you are in the project root folder and then update the .env file with your service credentials and workspace ID. For example, add these values to the .env file: WATSON_CONVERSATION_API_ROOT=https://gateway.watsonplatform.net/conversation/api WATSON_CONVERSATION_USERNAME=XXXXXXXXX WATSON_CONVERSATION_PASSWORD= XXXXXXXXX WATSON_CONVERSATION_WORKSPACE_ID= XXXXXXXXX Install dependencies by running the following commands: npm install cd client npm install cd . . Run the application by entering these commands: npm start cd client npm start Test the application by navigating to http://localhost:3000. Then, enter some text such as Show me a list of parks. Note: Some functionality will not work until you complete this lab.
FREE
Enhance the sample application
4 of 6
In this section, you will enhance the sample application by writing code and working with the Watson Conversation tool. Your enhancements will enable the server to return information about a park through the Watson Conversation response. Each time a user asks for details about (#tellmeabout) a particular park, the server should look up that park by name in the ParksDatabase. The lookup will return the park’s data object, which should then be added to the Watson Conversation response payload. You will also use conversation context in a variety of ways. First, you will use it to store the list of known (known to the system) national park names. Second, you will use context to keep track of the last park name referenced by the user. This tracking enables the server to respond with park details even if the user didn’t explicitly state a park name in the current utterance, for example, “What animals live there?” This section might be more challenging than the sections in previous labs. In this lab, some steps do include all the details needed to implement the step. This approach is meant to be a challenge. If you get stuck, don’t fret; simply look ahead that the solution video. Let’s get started: Open the file server/api/services/discourse/discourse.handler.js. This is where all of your code will go. This file also provides a good set of code comments describing how to implement the new functionality. These comments are your friend! Store the known parks in context. The server must set the known list of national parks: Modify the context object in the response r to include the parks property. Set the parks property equal to the array of known park names. Set the parks property only on the first dialog turn. Hint: You can get the array of parks by calling ParksDatabase.all() method. You also can determine the dialog turn by inspecting the context.system object and looking...

Continue Reading

Integrate the weather service introduction Lab 7: integrate the weather service

FREE
Integrate the Weather Company Data service into your server back end
4 of 6
Enhance the sample application to answer simple questions about the current weather at national parks. Write code to integrate the Weather Company Data service into the server. This section might be a bit challenging. Some steps do not include all the details needed to implement the step. This is meant to be a challenge. If you get stuck, don’t fret; simply review the solution video. You need to modify the discourseHandler(r) function in the server/api/services/discourse/discourse.handler.js file. Open the discourse.handler.js file in your file editor. Find the switch statement with the case for the tellmeabout intent. Create a new case for the weather intent. Create a function (or module) that invokes the Weather Company Data service’s current observations endpoint. Your function (or module) should accept the lat and lon value as input. It should use those values to invoke the following endpoint: ${WEATHER_API_ROOT}/api/weather/v1/geocode/${lat}/${lon}/observations.json The function or module should then return the response body from this above endpoint unaltered. Determine whether the park context variable is present in the response r. Look for context.park. If context.park is present, use ParksDatabase to look up the park and then get the park’s lat and lon. Note: If context.park is not present, you can’t get a lat and lon, and therefore can’t get the weather. In this case, return r lat unaltered. If context.park is present, pass the lat and lon to the function or module you created in Step 4. The response from Step 4 likely occurs asynchronously. So far, the discourseHandler(r) is synchronous. You need to adjust the return value of the discourseHandler(r) so that it can asynchronously handle this. After you make this change, you also need to update the server/api/services/discourse/index.js file to also handle the asynchronous response. If you get stuck, don’t fret; simply review the solution video. Extract the observation property from your function or module’s response value. Add the value of the observation property to r.output.weather. The UI expects the following code in the response: cardType = weather r.output.weather contains the weather response’s body.observation property. The UI needs this information to render properly.

Summary

More Courses by this Instructor